TypeError: type object argument after * must be an iterable, not int

30.5k views Asked by At

I am creating a Turtle program which will draw a Christmas Tree and some baubles. I want the baubles to have random colors and go to random points on the Christmas Tree. This is my code:

turtle.goto(random.randint(1,8)),(random.randint(1,8))

However when I run the program, this error appears:

TypeError: type object argument after * must be an iterable, not int

How do I fix this?

3

There are 3 answers

0
Moinuddin Quadri On

I do not know about turtle, but my best guess is that there is issue with your parenthesis:

turtle.goto(random.randint(1,8)),(random.randint(1,8))
#   Extra closing parenthesis  ^,^ extra opening

Change it to:

turtle.goto(random.randint(1,8), random.randint(1,8))
0
doctorlove On

goto takes an x and an optional y turtle.goto(x, y=None)

if we had

x = random.randint(1,8)
y = random.randint(1,8)

we could do

turtle.goto(x, y)

Or in one go, with some spaces for readability and extra chance of spotting mistakes, with as few braces as possible

turtle.goto( random.randint(1,8), random.randint(1,8) )

You don't need the extra paraens around the values you give to goto.

0
Srinivas On

I am not sure if this response is too late and if useful. I think you have two extra parentheses in the code. Just remove them as shown below. It shall work for you.

turtle.goto(random.randint(1,8),random.randint(1,8))