Python3-列表+条件判断-精简三盘两胜人机石头剪刀布

import random

list = ['石头','剪刀','布']

win_list = [['石头','剪刀'],['剪刀','布'],['布','石头']]
player_win = 0
computer_win = 0
all_cai = 0

while player_win < 2 and computer_win < 2:
    all_cai += 1
    print('''(0)石头
    (1)剪刀
    (2)布
    ***:''')
    ind = int(input('请选择对应的选项: '))
    computer = random.choice(list)
    player = list[ind]

    if player == computer:
        print('平局')
    elif [player,computer] in win_list:
        print('you win!!!')
        player_win += 1
    else:
        print('you lose!!!')
        computer_win += 1
if player_win == 2:
    print('一共对战%d次,player win' % all_cai)
if computer_win == 2:
    print('一共对战%d次,computer win' % all_cai)

发布了73 篇原创文章 · 获赞 4 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_27592485/article/details/99630673