0
点赞
收藏
分享

微信扫一扫

python写石头剪刀布的小游戏

覃榜言 2022-04-20 阅读 64
python
import random #引入随机模块
while True:
    choice=["石头","剪刀","布"]    
    users_choice=input("请输入你的选择(石头,剪刀,布):")
    computer_choice=random.choice(choice)
    print("------对战过程------")
    print("你的选择是:", users_choice)
    print("电脑的选择是:", computer_choice)
    if users_choice=="退出":
        break
    elif users_choice not in choice:
        print("你的输入有误,请重新输入\n")
    elif users_choice=="石头"and computer_choice=="剪刀" or users_choice=="布" and computer_choice=="石头" or users_choice=="剪刀" and computer_choice=="布":
        print("恭喜你赢了!\n")
    elif users_choice==computer_choice:
        print("平局!\n")
    else:
        print("抱歉,你输了!\n")
举报

相关推荐

0 条评论