python 画五环(简单方法到函数法)

2025-04-04 01:52:54

1、python通过turtle画一个圆import turtle as tt.penup()t.goto(-150,120)t.pendown()t.pensize(3)t.pencolor("blue")t.circle(50)

python 画五环(简单方法到函数法)

2、复制画一个圆的代码,到画五环,思路简单,学习者容易理解接受import turtle as tt.penup()t.goto(-150,120)t.pendown()t.pensize(3)t.pencolor("blue")t.circle(50)t.penup()t.goto(-40,120)t.pendown()t.pensize(3)t.pencolor("black")t.circle(50)t.penup()t.goto(70,120)t.pendown()t.pensize(3)t.pencolor("red")t.circle(50)t.penup()t.goto(-110,70)t.pendown()t.pensize(3)t.pencolor("yellow")t.circle(50)t.penup()t.goto(0,70)t.pendown()t.pensize(3)t.pencolor("green")t.circle(50)

python 画五环(简单方法到函数法)

3、缺点,重复代码,可以用函数循环的方法import turtle as tdef yuan(x,y,color): t.penup() t.goto(x,y) t.pendown() t.pensize(3) t.pencolor(color) t.circle(50)yuan(-150,120,"blue")yuan(-40,120,"black")yuan(70,120,"red")yuan(-110,70,"yellow")yuan(0,70,"green")

python 画五环(简单方法到函数法)

4、先画一个圆,到复制画一个圆的代码,到画五环,思路简单,学习者容易理解接受,但重复代码太多。使用定义函数,重复执行,精简代码,容易理解,更加明白定义函数的意义。

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢