首页 > 解决方案 > 新手:打印一个没有做出的选择

问题描述

import random

rock = '''
    _______
---'   ____)
      (_____)
      (_____)
      (____)
---.__(___)
'''

paper = '''
    _______
---'   ____)____
          ______)
          _______)
         _______)
---.__________)
'''

scissors = '''
    _______
---'   ____)____
          ______)
       __________)
      (____)
---.__(___)
'''

print("Welcome to the federaton of the ultimate Rock, Paper, Scissors Championship. Today you'll be facing the ultimate opponent... The Computer\n")
print("Type 'R' for Rock, 'P' for Paper and 'S' for Scissors. \nWe'll call 'Rock, Paper, Scissors says.... and you will input your answer after Shoot!!!'\n")
print("Rock, Paper, Scissors says.... ")

RPS_selection = input("Shoot!!! ")
print (RPS_selection)

if RPS_selection == "R" or "r":
  print(rock)
if RPS_selection == "P" or "p":
  print(paper)
else:
  print(scissors)

每次我运行以下代码时,Rock 似乎总是打印出我输入的内容。我很困惑,因为我正在使用带有“==”符号的 If 语句,这表明输入必须与我正在比较的内容相同。我知道这可以折射下来,但想了解我在这里缺少什么。任何和所有的帮助表示赞赏。谢谢!

标签: pythonif-statement

解决方案


这里是。修正你的条件如下:

if RPS_selection == "R" or RPS_selection == "r":
  print(rock)
elif RPS_selection == "P" or RPS_selection == "p":
  print(paper)
else:
  print(scissors)

推荐阅读