人机猜拳大战

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('你以为电脑是个小姐姐吗?')

发布了84 篇原创文章 · 获赞 10 · 访问量 8566

猜你喜欢

转载自blog.csdn.net/AK47red/article/details/104294909