开发中的应用场景
if 语句体验
if 语法进阶
综合应用
import random
people = int(input("玩家输入,石头(1)/剪子(2)/布(3):"))
compute = random.randint(1, 3)
print("玩家出拳 %d --- 电脑出拳 %d" % (people, compute))
if ((people == 1 and compute == 1) # 分析不到位, people == compute
or (people == 2 and compute == 2)
or (people == 3 and compute == 3)):
print("平局")
elif ((people == 1 and compute == 2)
or (people == 2 and compute == 3)
or (people == 3 and compute == 1)):
print("玩家胜利")
else:
print("电脑胜利")