Sean Rose
Sean Rose

Reputation: 3

TypeError: 'int' object is not iterable shape drawing

Hey everyone I am trying to learn Python and am currently trying to write a program to draw different shapes. Everything is working except the part where I define drawShapes at the end I get an error:

Traceback (most recent call last):
  File "/Users/seanrose/Desktop/Homework 4-1.py", line 126, in <module>
    drawShapes(nick, allshapes[i])
  File "/Users/seanrose/Desktop/Homework 4-1.py", line 121, in drawShapes
    for i in (numberofside):
TypeError: 'int' object is not iterable

Can anyone help?

https://i.sstatic.net/GKUip.png sorry here is an image to the code

or here is the part that isnt working wn = turtle.Screen() nick = turtle.Turtle() nick.color(penco) nick.pensize(penwid) wn.bgcolor(bcco)

def drawShapes(t, typeofshape):
totaldegrees = typeofshape[0]
numberofside = typeofshape[1]
lengthofsides = typeofshape[2]
whatkindofshape = typeofshape[3]
t.write(whatkindofshape)
for i in (numberofside):
    t.forward(lengthofsides)
    t.left(totaldegrees/numberofside)

for i in range(len(allshapes)):
drawShapes(nick, allshapes[i])

Upvotes: 0

Views: 471

Answers (1)

recursive
recursive

Reputation: 86084

From the error message, you seem to have this code:

for i in (numberofside):

Since numberofside is an integer, this will not work. If you want to iterate over the numbers from 0 to numberofside, try this.

for i in range(numberofside):

Upvotes: 1

Related Questions