Turtle program error. Please help!

Joined
Dec 10, 2023
Messages
1
Reaction score
0
I'm new so sorry if I posted wrong!

I keep getting a Traceback error and I'm not sure how to fix it.
Error.JPG


Python:
while True:
    askQuestion = input( 'Pick between a dog or a cat: ' )
    
    if askQuestion == "cat":
        print( 'Good choice!' )
        break
    elif askQuestion == "dog":
        print( 'Too bad! you get a cat. ' )
        break
    else:
        print( 'Please choose between a dog or a cat' )
    
askQuestion = input( 'pick a color for your cat! \nChoose Blue, red, or yellow: ' )
penSize = input( 'Please pick a pen size 1 through 100: ' )
penPace = input( 'Lastly, pick a pen speed, 1 through 100: ' )

import turtle

s = turtle.getscreen()

window = turtle.Screen()
window.bgcolor("white")
turtle.color(askQuestion)
turtle.pensize(penSize)
turtle.speed(penPace)


turtle.right(0)
turtle.forward(50)
turtle.left(45)
turtle.forward(30)
turtle.left(-90)
turtle.forward(35)
turtle.right(46)
turtle.forward(40)
turtle.right(-40)
turtle.forward(20)
turtle.left(-60)
turtle.forward(40)
turtle.left(-30)
turtle.forward(20)
turtle.right(-30)
turtle.forward(20)
turtle.right(-50)
turtle.forward(40)
turtle.right(15)
turtle.forward(40)
turtle.right(-50)
turtle.forward(10)
turtle.right(60)
turtle.forward(50)
turtle.right(-85)
turtle.forward(30)
turtle.left(65)
turtle.forward(30)
turtle.left(45)
turtle.forward(50)
turtle.right(30)
turtle.forward(30)
turtle.right(50)
turtle.forward(40)
turtle.right(70)
turtle.forward(35)
turtle.right(73)
turtle.forward(10)
turtle.left(-105)
turtle.forward(33)
turtle.left(78)
turtle.forward(30)
turtle.right(-45)
turtle.forward(20)
turtle.right(-30)
turtle.forward(55)
turtle.left(-55)
turtle.forward(40)
turtle.left(-59)
turtle.forward(210)
turtle.right(93)
turtle.forward(60)
turtle.right(50)
turtle.forward(10)
turtle.right(-45)
turtle.forward(45)
turtle.right(15)
turtle.forward(30)
turtle.right(-50)
turtle.forward(20)
turtle.right(-30)
turtle.forward(20)
turtle.left(-30)
turtle.forward(40)
turtle.left(-60)
turtle.forward(20)
turtle.right(-35)
turtle.forward(45)
turtle.right(46)
turtle.forward(35)
turtle.left(-90)
turtle.forward(30)
turtle.right(-40)
turtle.forward(20)
 
Joined
Jul 4, 2023
Messages
406
Reaction score
47
The input() function in Python always returns a string. That's why, when you're expecting numeric input (like in the case of penSize and penPace), you need to explicitly convert the string to the desired numeric type using int() or float().

[ code on-line ]
Python:
while True:
    askQuestion = input( 'Pick between a dog or a cat: ' )
   
    if askQuestion == "cat":
        print( 'Good choice!' )
        break
    elif askQuestion == "dog":
        print( 'Too bad! you get a cat. ' )
        break
    else:
        print( 'Please choose between a dog or a cat' )
   
askQuestion = input( 'pick a color for your cat! \nChoose Blue, red, or yellow: ' )
penSize = input( 'Please pick a pen size 1 through 100: ' )
penPace = input( 'Lastly, pick a pen speed, 1 through 100: ' )

print(type(askQuestion), type(penSize), type(penPace), '\n')


askQuestion = input( 'pick a color for your cat! \nChoose Blue, red, or yellow: ' )
penSize = float(input( 'Please pick a pen size 1 through 100: ' ))
penPace = float(input( 'Lastly, pick a pen speed, 1 through 100: ' ))

print(type(askQuestion), type(penSize), type(penPace))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,818
Messages
2,569,727
Members
45,661
Latest member
NadineBour

Latest Threads

Top