[英]How to move a turtle in Python using if-else and else statements?
需要帮助创建我的海龟,然后使用 Turtle Graphics 在 Python 中使用 if-else 和 else 语句通过命令移动它。 不知道如何开始
我不擅长解释事情,所以我只给你举个例子。 我希望你明白。
import turtle
import time
a = 1
b = 2
wn = turtle.Screen()
wn.title("If, Elif, Else Statements")
wn.bgcolor('black')
wn.setup(width=600, height=600)
wn.tracer(0)
if a > b:
a1 = turtle.Turtle()
a1.speed(0)
a1.shape("square")
a1.color("white")
a1.penup()
a1.hideturtle()
a1.goto(0,260)
a1.write("If Statement = True", align = "center", font = ("ds-digital", 24, "normal"))
time.sleep(10)
elif a < b:
a2 = turtle.Turtle()
a2.speed(0)
a2.shape("square")
a2.color("white")
a2.penup()
a2.hideturtle()
a2.goto(0,260)
a2.write("Elif Statement = True", align = "center", font = ("ds-digital", 24, "normal"))
time.sleep(10)
else:
a3 = turtle.Turtle()
a3.speed(0)
a3.shape("square")
a3.color("white")
a3.penup()
a3.hideturtle()
a3.goto(0,260)
a3.write("Else Statement = True", align = "center", font = ("ds-digital", 24, "normal"))
time.sleep(10)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.