关于变量的Python上的硬币翻转帮助

时间:2016-01-01 03:48:46

标签: python variables

注意:我已经在学校编写了gcse和东西,我体面但生锈,因为我没有多年编码。原谅我糟糕的编码,如果你能帮助提高代码效率,谢谢。

情况:我正在尝试编写一个简单的硬币翻转游戏,其中玩家以余额开始,然后如果他们赢了赌注则可以下注并加倍他们的钱。但是我无法将变量添加到一起,在搜索互联网时找不到可理解的答案,有人请帮我一个简单的解决方案,提前谢谢,汤姆:)

import random

print("Welcome to tomm's CSGOWild.com coinflip simulator!")
Starting_Money = input("How much money do you want to start with?")
Coin_Flip = random.randint(1, 2)

def Betting():

    Balance = ""
    Balance = Starting_Money + Balance
    Broke = "0"

    while Balance > Broke:

        Bet_Amount = input("How much money do you want to bet in this coin flip?")
        Coin_Side = input("What side do you want to choose: CT or T")
        Coin_Side_Coin = ""
        Temp_Balance = ""

        Coin = random.randint(1, 2)

        if Coin == 1:
        Coin_Side_Coin = "CT"

        elif Coin == 2:
        Coin_Side_Coin = "T"

        if Coin_Side == Coin_Side_Coin:
            Temp_Balance = Bet_Amount + Bet_Amount
            Balance = Balance + Temp_Balance
            print("Congratulations, you just won" + Temp_Balance + "in a coin flip!")

        elif Coin_Side != Coin_Side_Coin:
            Balance = Balance - Bet_Amount
            print("Sorry, you just lost" + Bet_Amount + "in a coin flip!")

Betting()

1 个答案:

答案 0 :(得分:0)

你需要将你的钱设置为花车,这样事情才能正常加起来。我正坐在NYE酒吧,所以我不能复制整个代码或测试以确保工作正常,但它应该。

(如果您的用户没有输入浮点数,系统会抛出TypeError。我建议在while中输入一个try/catch循环,这样您break没有例外被抛出。)

Starting_Money = float(input("How much money do you want to start with?"))

Balance = 0.0

Coin_Side_Coin = 0.0

Temp_Balance = 0.0