I am trying to create a RandomTurltes.py file but i keep getting an error when i
ID: 3771714 • Letter: I
Question
I am trying to create a RandomTurltes.py file but i keep getting an error when i am running it. the numturtles = numinput ("Turtlepower!", How many turtles?", 10) keeps giving me an error. The pgram is suppose to run 10 random turtles moving in different directions. Any help is greatly appreciated.
# create a number of turtle that move randomly
# and independently around the screen
from turtle import *
from turtle import *
# draw a starting circle
c1 = turtle ()
c1.speed(0)
c1.up() # lift pen
c1.sety(-100) # set y position
c1.down() # lower pen
c1.circle(100) # draw circle
c1.hideturtle() # hide turtle
turtleList = [] # our list of turtles
colors = ["red","blue","green","aqua","orange", "violet"]
shapes = ["turtle","square","circle","arrow"
numturtles = numinput("Turle power!", "How many turtles?", 10)
numturtles = int(numturtles)
for x in range (numturtles): # create our turtles
ninja = Turtle() # new turtle
turtleList.append (ninja) # add this turtle to our list
for x in range(numturtles): # make each turtle pretty
ninja= turtleList[x] # get this turtle from the list
ninja.speed(0)
ninja.pensize(2)
ninja.color(colors[x % len (colors)]) # why use modulus here?
ninja.shape(shaoes[x % len (shapes)]) # and here?
for x in range (numturtles): # set each turtle going a different direction
ninja = turtleList [x]
ninja.setheading(360 * x / numturtles)
ninja.forward(100)
# move turtles randomly
for x in range (100): # repeat 100 times
for turtles in turtleList:
deg = randrange(-60,61) # between -60 and 60
turtle.left(deg)
distance = randrange(5,21) # between 5 and 20
turtle.forward(distance)
Explanation / Answer
The lines num_turtles is wrong in the code.
the incorrect lines are:
numturtles = numinput("Turle power!", "How many turtles?", 10)
numturtles = int(numturtles)
The above two lines should be modified to
numturtles = int (input("Turle power!", "How many turtles? 10"))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.