我想在python中键入错误的字符后返回"input"



我想返回到;输入";在用户键入另一个不是"的字符之后;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()

您应该使用像这样的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()

您可以使用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
>>>

最新更新