栏目分类:
子分类:
返回
文库吧用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
文库吧 > IT > 软件开发 > 后端开发 > Python

python的石头剪刀布小程序,赶快体验吧

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python的石头剪刀布小程序,赶快体验吧

  新手入门python,想写个自己的小游戏,那就写个石头剪刀布小游戏吧,开始,上代码

#石头剪刀布程序
import random;
chuquan=["石头","剪刀","布"];
computer=random.choice(chuquan);
print("机器出拳是:",computer);
people = ''
people=input('请出拳:(石头、剪刀、布)');
while people not in chuquan:

    print('输入有误,请重新出拳')  # 当用户输入错误,提示错误,重新输入
    people= input()
if people==computer:
    print("平局")
elif (people=="石头" and computer=="剪刀") or (people=="剪刀" and computer=="布") or (people=="布" and computer=="石头"):
    print("您赢了");
else:
    print("您输了");

另外带充值检测判断:

#石头剪刀布带充值游戏
import random
print("======欢迎来到游戏中心======")
money=int(input("请充值金币:"))
print("===充值成功,开始游戏===")
while money> 0:
    print("===开始游戏===")
    chooce=["石头","剪刀","布"];
    computer_chooce=random.choice(chooce)
    people_choice=input("您出:石头,剪刀,布?");
    #判断用户输入是否错误
    while people_choice not in chooce:
        print('输入有误,请重新出拳')
        user_choice = input()
    if people_choice==computer_chooce:
        print("平局,电脑出",computer_chooce);
    elif (people_choice=="石头" and computer_chooce=="剪刀") or (people_choice=="剪刀" and computer_chooce=="布") or (people_choice=="布" and computer_chooce=="石头"):
        print("您赢了!电脑出:",computer_chooce);
        money += 1;
        print("恭喜加一元!",money)
    else:
        money -= 1;
        print("您输了!电脑出",computer_chooce)
        print("恭喜减一元!", money)
    cishu=input("您是否要继续?继续按回车键,退出按n");
    if cishu=='n':
        break;


转载请注明:文章转载自 www.wk8.com.cn
本文地址:https://www.wk8.com.cn/it/218875.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 wk8.com.cn

ICP备案号:晋ICP备2021003244-6号