【问题标题】:How to move a turtle in Python using if-else and else statements?如何使用 if-else 和 else 语句在 Python 中移动海龟?
【发布时间】:2021-11-26 05:19:27
【问题描述】:

需要帮助创建我的海龟,然后使用海龟图形在 Python 中使用 if-else 和 else 语句使用命令移动它。不知道怎么开始

【问题讨论】:

标签: python if-statement turtle-graphics


【解决方案1】:

我不擅长解释事情,所以我给你举个例子。希望你能理解。

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)

【讨论】:

    猜你喜欢
    • 2019-03-31
    • 1970-01-01
    • 1970-01-01
    • 2014-11-11
    • 2019-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多