等峰也等你

博客园 首页 新随笔 联系 订阅 管理
生成电脑的随机选择:使用 random.choice 函数从一组选项中随机选择电脑的出拳选项,将选择存储在另一个变量中
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('电脑胜')
posted on 2023-11-12 18:59  等峰也等你  阅读(52)  评论(0编辑  收藏  举报