python学习历程:猜拳

石头剪刀布,三局两胜!

import random

all_choice = ('石头', '剪刀', '布')

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

pc_win = 0

pl_win = 0

prompt = """(0)石头

(1)剪刀

(2)布

please choose 1/2/3:"""

while pc_win < 2 and pl_win < 2:

    computer = random.choice(all_choice)

    ind = int(input(prompt))

    player = all_choice[ind]

    if [player, computer] in all_winlist:

        pl_win += 1

        print('you: %s computer: %s' % (player, computer))

        print('your score: %s pc score: %s' % (pl_win, pc_win))

    elif [computer, player] in all_winlist:

        pc_win += 1

        print('you: %s computer: %s' % (player, computer))

        print('your score: %s pc score: %s' % (pl_win, pc_win))

    else:

        print('draw')

if pl_win == 2:

    print('you win !!!')

else:

    print('you lose !!!')

你可能感兴趣的:(python学习历程:猜拳)