python摇骰子游戏小案例

python摇骰子游戏小案例

小案例:
import random

#充值函数
def topup():
    global money
    n = input('充值金额(100元等于30个金币充值金额不低于100元):')
    num = int(n)
    if(num % 100 == 0 and num > 0):
        money = (num//100)*30
        print("*"*10+"充值成功"+'*'*10)
        print('当前账户:{}---您当前金币剩余:{}枚'.format(username, money))

#摇色子函数
def debit():
    global money
    first = random.randint(1, 6)
    last = random.randint(1, 6)
    money -= 2
    print('系统已经洗牌完毕!!!')
    guress = input('请您输入大小(大/小)')
    if(((first+last > 6) and guress == '大') or ((first+last <= 6) and guress == '小')):
        print('恭喜您本局游戏胜利!本局游戏奖励4和游戏金币')
        money += 6
        print('当前账户:{}---您当前金币剩余:{}枚'.format(username, money))
        answer = input('是否继续游戏吗?继续游戏需要扣除2枚金币(y/n)')
        debit()
    else:
        print('很遗憾本局游戏失败@[email protected]')
        print('当前账户:{}---您当前金币剩余:{}枚'.format(username, money))
        answer = input('是否继续游戏吗?继续游戏需要扣除2枚金币(y/n)')
        if(answer != 'y' or money < 2):
            print('........退出游戏...........')
        else:
            debit()


username = input('请输入您的账号:')
money = 4
answer = input('您确定进入游戏吗(y/n)')


if (answer == 'y'):
    if money < 2:
        answer = input(
            "当前账户:{}---您当前金币剩余:{}枚是否充值(y/n)".format(username, money))
        if(answer == 'y'):
            topup()
            debit()
    else:
        if(answer == 'y'):
            print('欢迎{}进入游戏'.format(username))
            while True:
                debit()

注:学了一点点python写的小案例

猜你喜欢

转载自blog.csdn.net/zszcc/article/details/109066590