'石头0', '剪刀1', '布2'
'''
玩家 计算机
0 1 玩家获胜
0 2 计算机获胜
1 0 计算机获胜
1 2 玩家获胜
2 0 玩家获胜
2 1 计算机获胜
'''
import random player = int(input("请输入整数['石头0', '剪刀1', '布2']:")) while not player in [0,1,2]: player = int(input("输入错误,请重新输入整数0,1,2:")) computer = random.randint( 0,2 ) # compute = random.choice([0,1,2]) ls = ['石头', '剪刀', '布'] # print(f'玩家出:{ls[player]}, 计算机出:{ls[computer]}{computer}') #查看计算机出的数字 print(f'玩家出:{ls[player]}, 计算机出:{ls[computer]}') if (player == 0 and computer == 1) or (player == 1 and computer == 2) or (player ==2 and computer ==0): print("玩家获胜!") elif player == computer: print('平局!') else: print('计算机获胜!') ''' 玩家 计算机 0 1 玩家获胜 0 2 计算机获胜 1 0 计算机获胜 1 2 玩家获胜 2 0 玩家获胜 2 1 计算机获胜 '''
标签:布锤,游戏,剪子,玩家,player,computer,ls,获胜,计算机 From: https://www.cnblogs.com/bravesunforever/p/18326807