import turtle
t = turtle.Turtle()
t.shape("turtle")
while True:
t.penup()
t.goto(300, 0)
t.write("If the turtle comes here, it's a positive number.")
t.goto(0, 300)
t.write("If the turtle comes here, it's 0."")
t.goto(-300, 0)
t.write("If the turtle comes here, it's negative.")
t.goto(0, 0)
t.pendown()
n = turtle.textinput("", enter a number: ")
#s = int(n)
if( n == 'a' ):
break
elif( int(n) > 0 ):
t.goto(300, 0)
elif( int(n) == 0 ):
t.goto(0, 300)
elif( int(n) <= 0):
t.goto(-300, 0)
elif( n == 'b' ):
break
t.clear()
I understand that when the variable n is entered as input, it is received as a string. If you receive a positive, zero, or negative number with an infinite loop, draw a line and try to end when you receive 'a', 'b'.
Questions
python
I don't know much about the module, but just looking at the loop, I think we need to fix it like this.
import turtle
t = turtle.Turtle()
t.shape("turtle")
t.penup()
t.goto(300, 0)
t.write("If the turtle comes here, it's a positive number.")
t.goto(0, 300)
t.write("If the turtle comes here, it's 0."")
t.goto(-300, 0)
t.write("If the turtle comes here, it's negative.")
t.goto(0, 0)
t.pendown()
#s = int(n)
while True:
n = turtle.textinput("", enter a number: ")
if( n == 'a' ):
break
elif( int(n) > 0 ):
t.goto(300, 0)
elif( int(n) == 0 ):
t.goto(0, 300)
elif( int(n) <= 0):
t.goto(-300, 0)
elif( n == 'b' ):
break
t.clear()
© 2024 OneMinuteCode. All rights reserved.