好吧,所以我要做的就是让这个程序让用户输入退出,随机乱跑,或者删除已经绘制的内容并再次随机运行。
我有很好的运行部分,我需要帮助获取我的输入(称为"消息")实际运行选项" w"和" e"到目前为止它所做的只是绘制一个新的随机运行。 (我可能只是错误的乌龟命令,我无法弄清楚)。我相信我使用了错误的单词(if,while,elif)以使菜单正常工作。我也认为跳转功能不起作用,或者我在其他功能中重置它。
import turtle as t
import random as r
count=0
t.speed(0)
x=r.randint(1,100)
y=r.randint(1,100)
#----------------------------------------
""" sets the turtle to a new starting point"""
def jumpto(x,y):
t.penup()
t.goto(x,y)
t.pendown()
return None
def randomrun ():
"""runs turtle around 1000 steps randomly"""
count=0
while count <1000:
count+=1
t. forward (6)
t.left(r.randint(0,360))#360 degree choice of rotation
t.dot(10)#puts a dot at the end of the run of lines
count=0#resets count so it can do it again
x=r.randint(1,100)
y=r.randint(1,100)
message= input("q to quit \nw to walk randomly for 1000 steps \ne to erase screen and walk randomly ")
return message
#-------------------------------------------
message= input("q to quit \nw to walk randomly for 1000 steps \ne to erase screen and walk randomly ")
if message =="w":
randomrun()
jumpto(x,y)
if message == "q":
print(" have a nice day")
if message== "e":
t.clear()
randomrun()
jumpto(x,y)
答案 0 :(得分:1)
忽略来自return
的{{1}}。无论如何,重复输入提示是个坏主意。将其从randomrun
移除return
,然后以randomrun
循环结束。
input