繁体   English   中英

如何询问用户是否希望代码重新开始

[英]how to ask the user if they want the code to start again

我刚开始学习 python Nat5 课程,所以如果答案非常明显,我很抱歉,但我想要做的是询问用户是否希望重新启动代码并再次询问用户是否输入错误的答案

print("would you like to ask again?")
go = input("enter yes/y or no/n")

if(go == 'y') or (go == 'yes'):
#replay here
elif(go == 'n') or (go == 'no'):
    exit()
else:
print("It's a yes or no question")
#ask to replay again

我不知道这是否是最佳做法,但它对我有用,而且我没有遇到任何问题。 将代码放入 function

def code():
    #insert the code here

然后调用 function

if (go=='y'):
   code()

还值得注意的是,您还需要在代码末尾调用 function 以便它真正运行第一次。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM