猜拳游戏 & 导入模块方法
'''
0 石头 1 剪刀 2 布
1.玩家出拳
2.电脑出拳
3判断输赢
'''
player = int(input('0 石头 1 剪刀 2 布,玩家请出拳:'))
computer = 1
if (player == 0 & computer == 1) or (player == 1 & computer == 2) or (player == 2 & computer == 0):
print('恭喜你获得胜利')
elif (player == 0 & computer == 0) or (player == 1 & computer == 1) or (player == 2 & computer == 2):
print('平局')
elif (player == 0 & computer == 2) or (player == 1 & computer == 0) or (player == 2 & computer == 1):
print('很遗憾你输了!!')
- 导入随机数模块
import random
"""
1.导入模块 import random
2.使用模块功能
3。random.randint()
"""
player = int(input('0 石头 1 剪刀 2 布,玩家请出拳:'))
computer = random.randint(0, 2)
if (player == 0 & computer == 1) or (player == 1 & computer == 2) or (player == 2 & computer == 0):
print('恭喜你获得胜利')
elif (player == 0 & computer == 0) or (player == 1 & computer == 1) or (player == 2 & computer == 2):
print('平局')
elif (player == 0 & computer == 2) or (player == 1 & computer == 0) or (player == 2 & computer == 1):
print('很遗憾你输了!!')