python - 新手:打印一个没有做出的选择
问题描述
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 语句,这表明输入必须与我正在比较的内容相同。我知道这可以折射下来,但想了解我在这里缺少什么。任何和所有的帮助表示赞赏。谢谢!
解决方案
这里是。修正你的条件如下:
if RPS_selection == "R" or RPS_selection == "r":
print(rock)
elif RPS_selection == "P" or RPS_selection == "p":
print(paper)
else:
print(scissors)
推荐阅读
- r - 为什么包含 load() 命令的附加代码不起作用?
- sql - 生成一个总和报告,具有两个不同的产品属性
- python - 迭代问题,内减法不能正常工作
- python - 如何使用 Selenium 在 Python 中的 ::before 和 ::after 跨度之间打印封闭文本?
- slack - 无法通过python使用slack api将上传的文件附加到消息
- html - VBA 语言翻译器 UDF 不使用特殊字符
- rust - Rust 是否会缩短生命周期以满足对其定义的约束?
- spring-boot - 我什么时候应该在 java 8 中使用 mapstruct 或转换器以避免容易出错?
- python - 遍历 pandas 数据框,从另一行中的数据更新值,然后删除另一行
- .net - .NET 5 未显示在注册表中