Python实现石头剪刀布小游戏

import random
player_score=0
computer_score=0
# 输出
print('''
* * * * * * * 欢迎来到人机对战小游戏 * * * * * * *  
              石头      剪刀      布
* * * * * * * * * * * * * * * * * * * * * * * * * *
''')
player_name=input('请输入玩家的姓名:> ')
print('1.貂蝉 2.曹操 3.诸葛亮')
choice=eval(input('请选择电脑角色:> '))
if choice==1:
    computer_name='貂蝉'
elif choice==2:
    computer_name='曹操'
elif choice==3:
    computer_name='诸葛亮'
else:
    computer_name='匿名'
print(player_name,' VS ',computer_name)
while True:
    # 玩家出拳
    player_first=eval(input('-------请出拳: 1. 石头   2. 剪刀   3. 布-------\n'))
    if player_first==1:
        player_first_name='石头'
    elif player_first==2:
        player_first_name='剪刀'
    elif player_first==3:
        player_first_name='布'
    else:
        player_first_name='石头'
        player_first=1
    # 电脑角色出拳
    computer_first=random.randint(1,3) # [1,3]
    if computer_first==1:
        computer_first_name='石头'
    elif computer_first==2:
        computer_first_name='剪刀'
    elif computer_first==3:
        computer_first_name='布'
    print(player_name,'出拳:> ',player_first_name)
    print(computer_name,'出拳:> ',computer_first_name)  
    if player_first==computer_first:
        print('平局')
    elif (player_first==1 and computer_first==2) or (player_first==2 and computer_first==3) and (player_first==3 and computer_first==1):
        print('玩家:',player_name,'胜')
        player_score+=1
    else:
        print('电脑:',computer_name,'胜')
        computer_score+=1
    answer=input('再来一局不?y/n')
    if answer!='y':
        break
print('------------------------------')
print(player_name,player_score)
print(computer_name,computer_score)
print('------------------------------')
if player_score==computer_score:
    print('平局')
if player_score>computer_score:
    print(player_name,'胜利')
if player_score<computer_score:
    print(computer_name,'胜利')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱听歌的阿漓

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值