【发布时间】:2020-12-14 15:03:33
【问题描述】:
如果用户输入了正确的大写单词,我会收到“您犯了错误”的响应。为什么user_choice.lower() 不能像我预期的那样工作?我哪里做错了?
import random
rock_paper_scissors = ("rock", "paper","scissors")
cpu_choice = random.choice(rock_paper_scissors)
user_choice = input("Rock, paper or scissors ? Enter your choice: ")
if user_choice.lower() != "rock" or "paper" or "scissors":
print("You made a mistake. Please try again")
user_choice = input("Rock, paper or scissors ? Enter your choice: ")
while cpu_choice == user_choice.lower():
print ("--------------------------------------------------------")
print(f"CPU: {cpu_choice.upper()} vs YOU: {user_choice.upper()}. It's a tie. Try again!")
print ("--------------------------------------------------------")
user_choice = input("Rock, paper or scissors ? Enter your choice: ")
【问题讨论】:
-
if user_choice.lower() != "rock" or "paper" or "scissors"不是检查多个值的正确方法。看到这个问题stackoverflow.com/q/15112125/494134 -
查看@toRex 的回答