Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need help with a python function

DHulse94DHulse94 Posts: 1Member
I have a function that draws a star (this works) and I have to call that function a certain amount of times, given by the input. The colors of the stars have to be generated randomly, the length of each side of the star has to be generated randomly, and the placing (x,y) coordinate of the star. In other words, I have to make a bunch of differently sized, different color stars scattered around the page. Here is what I have and I keep getting a type error saying the type 'int' has no len().

FOR DRAWING THE STAR

def star(color,length,x,y):
turtle.penup()
turtle.color(color)
turtle.goto(x,y)
turtle.forward(length)
turtle.pendown()
count = 0
while (count < 5):
turtle.forward(length)
turtle.right(144)
turtle.forward(length)
count +=1
print (star("black",50,200,-100))

FOR DRAWING SEVERAL STARS

def color():
Question = int(input("How many stars do you want? "))
count = 0
while (count < Question):
rnum = randrange(0,5)
if (rnum == 0):
turtle.color("red")
elif (rnum == 1):
turtle.color("blue")
elif (rnum == 2):
turtle.color("yellow")
elif (rnum == 3):
turtle.color ("green")
else:
turtle.color("black")
turtle.penup()
x = randrange(-280,280)
y = randrange(-200,200)
turtle.goto(x,y)
turtle.pendown()
turtle.color(rnum)
rnum2 = randrange(5,70)
turtle.forward(rnum2)
count += 1
print (star)
print (color())
Sign In or Register to comment.