Question:
I am building a miniproject using the turtle module . The script works really well until i add a list of assertion tests. Does anyone know why the turtle keeps moves to different coordinates before going to the input coordinate Δy
?
Repl link:
https://replit.com/@jonathanessombe/new-attempt#main.py
import turtle
Thomas = turtle.Turtle()
Thomas.shape("turtle")
Thomas.penup()
screen = turtle.Screen()
screen.setup(1000, 1000)
Δy = (input("How high do you want Thomas to go Vertically?")).strip()
def Thomas_task(Δy):
try:
if type(int(Δy)) != int:
raise ValueError
if int(Δy) > 200 or int(Δy) < -200:
Thomas.fd(-10)
return " Hey, thats not a number between 200 and -200!"
Thomas.goto(0, int(Δy))
if 150 < int(Δy) <= 200:
return " This is very high!"
if 100 <= int(Δy) <= 150:
return " This is high!"
if 0 <= int(Δy) < 100:
return " This is high but not high enough!"
if 0 > int(Δy) >= -100:
return " This is low but not low enough!"
if -100 >= int(Δy) > -150:
return " This is low!"
if -150 > int(Δy) > -200:
return " This is very low!"
except ValueError:
Thomas.fd(-10)
return " Please enter a valid integer!"
assert Thomas_task("uolkhdaw") == " Please enter a valid integer!"
assert Thomas_task("300") == " Hey, thats not a number between 200 and -200!"
assert Thomas_task("20") == " This is high but not high enough!"
assert Thomas_task("140") == " This is high!"
assert Thomas_task("160") == " This is very high!"
assert Thomas_task("-90") == " This is low but not low enough!"
assert Thomas_task("-140") == " This is low!"
assert Thomas_task("-180") == " This is very low!"
assert Thomas_task("-sadw") == " Please enter a valid integer!"
Thomas.write(Thomas_task(Δy))