使用python做一个简单的互动功能(学习)


import random

gold = 0
while True:
    print('现在拥有的%d' % gold)
    if gold >= 5:
        print('_________准备开始游戏___________')
        gold -= 5
        dice1 = random.randint(1, 6)
        dice2 = random.randint(1, 6)
        dice3 = dice1 + dice2
        guess = input('请输入大/小')
        if dice3 < 6 and guess == '小' or dice3 >= 6 and guess == '大':
            print('你赢了')
            gold += 2
            print('当前拥有的金币为%d,' % gold)
            goon = input('还继续吗?y/n')
            if goon == 'n':
                break
        else:
            print('你输了')
            print('当前拥有的金币为%d,' % gold)
            goon = input('还继续吗?y/n')
            if goon == 'n':
                break
    else:
        sure = input('确定充值吗?充值请输入1\n')
        if sure == '1':
            res = int(input('当前拥有的金币为%d,请输入充值数量' % gold))
            gold += res * 1.2
            print('充值%d 充值系统赠送10个,一个有%d' % (res, gold))
        else:
            break