人机猜拳大战

import random
game_num = player_win_times = computer_win_times = 0
while True:
    computer = random.randint(0, 2)
    game = ['石头', '剪刀', '布']
    player = int(input('[0 -> 石头    1 -> 剪刀     2 -> 布      3 -> 退出]    '))
    while player not in [0, 1, 2, 3]:
        print('>'*10 + 'Input error, Please input again: ')
        player = int(input('[0 -> 石头    1 -> 剪刀     2 -> 布      3 -> 退出]:   '))
    if player == 3:
        break
    print()
    print("你出了%s" %game[player])
    print('电脑出了%s' %game[computer])
    if player == 0 and computer == 1 or player == 1 and computer == 2 or player == 2 and computer == 0:
        print("你赢了!")
        player_win_times += 1
        game_num += 1
    elif player == 0 and computer == 2 or player == 1 and computer == 0 or player == 2 and computer == 1:
        print("你输了!")
        computer_win_times += 1
        game_num += 1
    else:
        print("平局!")
        game_num += 1
    print()
print()
print("战况统计" + '>'*30)
print("共计 %d回合,你赢了 %d回合,电脑赢了 %d回合" %(game_num, player_win_times, computer_win_times))
if player_win_times > computer_win_times:
    print('你咋这么厉害呢')
elif player_win_times < computer_win_times:
    print('DSG!')
else:
    print('你以为电脑是个小姐姐吗?')

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值