python-3.x - Python Card 游戏有助于简化 if/elif 语句
问题描述
如果您想学习如何玩它,我制作了一个翻牌游戏,请访问 https://www.youtube.com/watch?v=CCxs-tu8tOU
numbers = [0, 1, 0, 0, 1, 1, 0]
options = []
for num in range(0, len(numbers)):
if numbers[num] == 1:
options.append(num)
choice = int(input("Here's a list of cards: {}, your options are {}: ".format(numbers, options)))
下面的代码太长了,我需要帮助来简化它
if choice in options:
numbers[choice] = '.'
if numbers[choice-1] == 0:
numbers[choice-1] = 1
elif numbers[choice-1] == 1:
numbers[choice-1] = 0
if numbers[choice+1] == 0:
numbers[choice+1] = 1
elif numbers[choice+1] == 1:
numbers[choice+1] = 0
解决方案
推荐阅读
- r - 卡方比较一个参考组与另外两个组
- javascript - 从汇总 dist 文件中删除绝对文件路径名
- css - 为什么输入字段比它的父 div 更宽?
- python - 从 Azure Functions 调用时,Django API 引发 403 错误
- android - 如何使用 LiveData 将不同数据类型的多个数据从 ViewModel 传递到 Activity/Fragment
- c# - C# 模式匹配任务
并获得它的价值 - python - 使用 str(df) 后如何取回 DataFrame?
- python - 全局禁用 TensorFlow 断言?
- c++ - Julia:调用使用自定义内核的 ArrayFire 自定义函数,ArgumentError:无法将 NULL 转换为字符串
- python - 从文本文件创建一个字典,其中包含一个键和一个由多个属性组成的集合