我需要编写一个函数,根据这个人想要多少颗星星的问题来随机绘制星星。a=color,b=length 和 c,d 是起始坐标。我不确定我哪里出错了,任何提示、提示或帮助将不胜感激。
import turtle
from random import*
def star(a,b,c,d):
x=5
y=0
turtle.color(a)
turtle.begin_fill()
turtle.penup()
turtle.goto(c,d)
turtle.pendown()
while x>0:
turtle.forward(b)
turtle.right(144)
turtle.forward(b)
x-=1
turtle.end_fill()
star('red',100,0,0)
def random_color():
randvar=randrange(0,5)
if randvar==0:
return ('red')
elif randvar==1:
return ('blue')
elif randvar==2:
return ('green')
elif randvar==3:
return ('yellow')
else:
return ('black')
def length():
randvar=randrange(5,71)
def x():
randvar=randrange(-280,281)
def y():
randvar=randrange(-200,201)
def night_sky():
z=int(input('How many stars do you want?'))
a=random_color
b=length
c=x
d=y
while z>0:
star(a,b,c,d)
z-=1