好的,所以我要做的是让这个程序要求用户输入退出,随机运行,或者删除已经绘制的内容,然后再次随机运行
我有运行周围的部分下来罚款,我需要帮助我的输入(称为“消息”),以实际运行选项“w”和“e”到目前为止,它所做的是绘制一个新的随机运行我可能只是搞错了海龟的命令,我想不出来)。我相信我用错了词(if,while,elif)让菜单正常工作。我还认为jumpto函数不起作用,或者我正在我的另一个函数中重置它
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)
来自
randomrun
的return
被忽略。无论如何,重复输入提示是个坏主意。从randomrun
中删除它和return
,并以input
循环结束相关问题 更多 >
编程相关推荐