Python猜拳小游戏
直接上代码
1.这里调用了 random函数,产生随机数
import random
player = int(input('请你出拳:1--剪刀;2--石头;3--布:'))
print(f'你出的是{player}')
cumputer = random.randint(1,3)
# 玩家赢
if (player == 1 and cumputer == 3) or (player == 2 and cumputer == 1) or (player == 3 and cumputer == 2):
print(f'cumputer出的是{cumputer},你赢了')
elif (player == 1 and cumputer == 1) or (player == 2 and cumputer == 2) or(player == 3 and cumputer == 3):
print(f'cumpter出的是{cumputer},平局')
else:
print(f'cumpter出的是{cumputer},你输了')
运算结果:
请你出拳:1--剪刀;2--石头;3--布:1
你出的是1
cumpter出的是1,平局