python - 程序将向用户询问套件并打印该套件
问题描述
我试图让用户输入一个套件,如果该套件不在字典中,那么它不会在字典中打印,但输入是一个套件,然后它会打印该套件
我已经尝试了我知道该怎么做的一切
a = {'hearts':"hearts",'diamonds':"diamonds",'spades':"spades",'clubs':"clubs"}
while b=input("Pick a Suite"):
if a = b:
print(b)
else:
print(a, "not a suite")
print("foo not a suite")
再次,如果用户键入正确的套件,那么它将打印套件,如果不是,它将打印“foo not a suite”
解决方案
a = {'hearts': "hearts", 'diamonds': "diamonds", 'spades': "spades", 'clubs': "clubs"}
key = input("Pick a Suite, please enter: ")
if key in a:
print(a[key])
else:
print('There is no element with key "' + key + '" in dict')
推荐阅读
- wordpress - 如何完全删除wordpress主题“二十九”的标题
- sql - SQL 获取数据 current_Datetime 减去 5 年?
- ios - Crashlytics 是否会在应用扩展上发生先前崩溃时调用 CrashlyticsDelegate?
- r - 如何在 CentOS 上安装最新版本的 R(目前为 4.0.0)?
- bash - 在写入时更改终端输出(日志)文件
- c - 双重递归中的 malloc 和 free
- bluetooth - 关于蓝牙服务发现协议的基本问题
- python - 如何在 Python 中将列名更改为工作日
- vba - 在 PowerPoint 中自动从 4:3 转换为 16:9,包括内容
- javascript - 如何让 setInterval 函数工作?