![](/img/trans.png)
[英]How do I get my (if “input” in list) to check every letter of the input and not just the first letter of input?
[英]How do I get my first input to be invalid
基本上,当我运行代码时,如果我为第一个输入输入了一个无效的答案,它仍然会继续到第二个输入。 如果我为第一个输入输入无效答案,我正在尝试获取它它再次启动循环。 (对不起,我很新)
play_again = "y"
# Collects both players name and gives error if not alphabet
while play_again == "y":
def setup():enter code here
playerOne = input("What is player 1's name: ")
playerTwo = input("What is player 2's name: ")
if playerOne.isalpha() == True and playerTwo.isalpha() == True:
print("Valid names")
else:
print("Invalid name")
setup
您正在检查玩家一和二在进入后同时无效。 您的代码从上到下运行,因此在检查是否有效之前需要两个输入。 您可以通过替换它来解决此问题。
playerOne = input(...)
if playerOne.isalpha():
Print("name 1 is valid")
Else:
Print("name is invalid please try again")
# here you have some options you could end your program using exit() or put this method in a loop to keep asking for a new name pick one and add it in and it will repeat the check
player two = ... # you get the point just rewrite your previous code
只需询问您是否需要我提到的任何选项的任何帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.