【发布时间】:2021-11-26 05:19:27
【问题描述】:
需要帮助创建我的海龟,然后使用海龟图形在 Python 中使用 if-else 和 else 语句使用命令移动它。不知道怎么开始
【问题讨论】:
-
好吧,你必须至少提供一些东西来作为答案的基础。你必须提出一个具体的问题。
标签: python if-statement turtle-graphics
需要帮助创建我的海龟,然后使用海龟图形在 Python 中使用 if-else 和 else 语句使用命令移动它。不知道怎么开始
【问题讨论】:
标签: python if-statement turtle-graphics
我不擅长解释事情,所以我给你举个例子。希望你能理解。
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)
【讨论】: