python经典程序练习题7:绘制一个红色的五角星图案

我的答案:

import turtle as t
t.pencolor('red')
for i in range(5):
    t.forward(100)
    t.right(144)

嵩天老师的优秀答案:

from turtle import *
fillcolor("red")
begin_fill()
while True:
    forward(200)
    right(144)
    if abs(pos()) < 1:  #查看画笔是否回到原点,回到原点时为真
        break           #回到原点,跳出循环
end_fill()

begin_fill()  pos()    end_fill() 均为turtle库内的函数。

猜你喜欢

转载自blog.csdn.net/qq_41149269/article/details/81090362
今日推荐