生成电脑的随机选择:使用 random.choice 函数从一组选项中随机选择电脑的出拳选项,将选择存储在另一个变量中标签:31,random,choice,player,computer,print,剪刀 From: https://www.cnblogs.com/csfsz/p/17827590.html
print('猜拳游戏开始:')
player = input('请出拳(石头/剪刀/布):\n')
computer = random.choice(['石头', '剪刀', '布'])
print(f'电脑出拳:{computer}')
if player == computer:
print('平局')
elif (player == "石头" and computer == "剪刀") or \
(player == "剪刀" and computer == "布") or \
(player == "布" and computer == "石头"):
print("玩家胜利!")
else:
print('电脑胜')