我编写了一个小循环来阻止用户使用无效的输入;但是,如果用户输入了错误的输入,它会不断地要求用户输入。baseLet、secLet、thirdLet和forLet都是包含字符的列表。代码应该告诉用户是否输入了任何列表中没有的字符,如果有,则让他们重新输入。你知道吗
enchan = list(input("Enter your runes:"))
for z in enchan:
if not(z in baseLet or z in secLet or z in thirdLet or z in forLet):
valid = False
x = 0
while not(valid):
x = 0
enchan = list(input("Invalid character entered. Enter your runes:"))
while not(x < len(enchan)):
valid = True
for z in enchan:
if not(z in baseLet or z in secLet or z in thirdLet or z in forLet):
valid = False
x += 1
恕我直言,我对编码还比较陌生,有可能是一个愚蠢的错误,但这是我来这里(学习)的主要原因。你知道吗
这应该起作用:
您可以使用一个函数来检查您的输入是否是列表的一部分,并设置一个标志来停止while循环。你知道吗
相关问题 更多 >
编程相关推荐