无法让我的输入重复或删除

Cant get my input to repeat or delete

好吧,所以我要做的是让这个程序要求用户输入退出,运行随机,或擦除已经绘制的内容并运行随机再次.

我的 运行ning 部分没问题,我需要帮助让我的输入(称为 "message")实际 运行 选项 "w" 和 "e" 到目前为止它所做的只是绘制一个新的随机数 运行。 (我可能只是有错误的 turtle 命令,我无法弄清楚)。我相信我使用了错误的词(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 循环结束。

while True:
    message = input("q to quit\n"  # use implicit string joining
                    "w to walk randomly for 1000 steps\n"
                    "e to erase screen and walk randomly\n"
                    "> ")[:1].lower()  # forgive non-exact input
    if message == "q":
        print("Have a nice day!")
        break
    elif message =="w": 
        randomrun()
        jumpto(x,y)
    elif message == "e":
        t.clear()
        randomrun()
        jumpto(x,y)
    else:
        print("Input not recognized; try again.")