【问题标题】:I want to return to "input" after type wrong character in python [closed]在python中输入错误字符后我想返回“输入”[关闭]
【发布时间】:2020-12-15 13:43:48
【问题描述】:
我想在用户键入另一个不是“n”字符串的字符后返回“输入”,
条目数据是一个“输入”,使用户按回车键继续或输入“n”,但如果用户输入另一个字符串,控制台关闭
_WriteList = input("Write a textfile with the file list? (Enter) Yes or (n) No: ")
if bool(_WriteList) == False:
sevenZipListWrite()
elif _WriteList == "n":
sevenZipList()
【问题讨论】:
标签:
python
if-statement
input
【解决方案1】:
你应该使用这样的 while 循环来做到这一点
_WriteList = input("Write a textfile with the file list? (Enter) Yes or (n) No: ")
while _WriteList != 'n':
sevenZipListWrite()
_WriteList = input("Write a textfile with the file list? (Enter) Yes or (n) No: ")
sevenZipList()
【解决方案2】:
你可以使用while循环:
>>> user_input = ''
>>> while user_input != 'n':
... user_input = input("Enter your input: ")
...
Enter your input: a
Enter your input: 1
Enter your input: 3
Enter your input: n
>>>