私信  •  关注

Azy_Crw4282

Azy_Crw4282 最近创建的主题
Azy_Crw4282 最近回复了
5 年前
回复了 Azy_Crw4282 创建的主题 » 用python验证输入

您的输入不正确,因为输入返回的是string类型,并且您正在使用int类型进行检查,因此请更改循环中的类型。而且,你不能使用 or 如果希望在其中一个情况为真时终止,则必须使用 and .

print("This program simulates a 'rock paper scissor' game.")
print("The rules are as follows: rock beats scissor, paper beats rock, and scissor beats paper. \n")

print("This program simulates a 'rock paper scissor' game.")
print("The rules are as follows: rock beats scissor, paper beats rock, and scissor beats paper. \n")

#get user input
user_choice = input("Please choose from the following:  \n"
                    " 1 for scissor \n"
                    " 2 for rock \n"
                    " 3 for paper. \n")

#validate input so user only enters 1, 2, or 3

while user_choice != '1' and user_choice != '2' and user_choice != '3':
    user_choice = input("Please enter only '1' for scissor, '2' for rock, or '3' for paper: ")

#convert input to int
int_user_choice = int(user_choice)