【问题标题】:My equation seems to no be working, but looks right我的方程式似乎不起作用,但看起来正确
【发布时间】:2018-10-19 07:46:50
【问题描述】:

我是一个业余的 Python 程序员,我正在尝试做一个双倍或没有的赌博游戏,基本上你下注一定数量的钱,你有机会获得双倍的投入或失去你投入的资金。

似乎当我运行这个脚本时,我下了赌注,但钱标签没有改变,我不确定如何调试。

from appJar import gui
import random

# GUI Tab Name
win = gui('Double or Nothing')
# Starting Money

# Declares the odds
array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# declaring the random array choice.

random = int(random.choice(array))

# starting money amount.

money = 500

# This is the define for the 'Insert Bet' button.
def press(name):

    bet = int(win.getEntry('Bet'))

    if name == 'InsertBet':
        win.setLabel('outcome', int(random))
        outcomes = int(win.getLabel('outcome'))
# The formula used to deduct and add Winnings
# If random is a number larger than seven, i would like to deduct
        if random >= int(7) :
            money == (int(money) - bet) + (bet * 2)
            win.setLabel('showMon', '$' + str(int(money)))

        elif random <= int(6) :
            money == int(money) - bet
            win.setLabel('showMon', '$' + str(int(money)))


# To Display How much money you have.

win.addLabel('showMon', '$' + str(int(money)))
win.addLabel("Insert amount money")
win.addEmptyLabel('outcome')
win.addEntry('Bet')
win.addButton('Insert Bet', press)

# start the GUI
win.go()

【问题讨论】:

标签: python python-3.x gambling


【解决方案1】:

条件中的名称需要与初始化按钮的名称相匹配:

变化:

if name == 'InsertBet':

到:

if name == 'Insert Bet':

【讨论】:

    【解决方案2】:

    您的问题您的问题之一在于以下两行:

    money == (int(money) - bet) + (bet * 2)
    ...
    money == int(money) - bet
    

    这是检查money 是否分别等于(int(money) - bet) + (bet * 2))int(money) - bet。使用=money 设置为一个值。

    另一个问题,正如blhsing's answer 所指出的那样,是您正在检查"Insert Bet" 按钮是否被称为"InsertBet",它不是;因此,您根本没有运行按钮按下代码!

    if name == 'InsertBet':
    

    应该是

    if name == 'Insert Bet':
    

    第一个错误几乎总是反过来!恭喜你对你的错误很有创意。 :-p

    【讨论】:

    • 谢谢你试图帮助我,但它似乎仍然处于我认为我需要在某个地方使用循环的相同状态,但我不确定我会在哪里,但改变了 = =太=似乎没有解决办法。 ://
    • @LukeKendon blhsing 的回答给出了另一个问题,我没有注意到。
    • 我已经修复了之前的问题,
    • 但是现在当我尝试下注 10 然后我按下按钮
    • 我得到一个错误 money = int(money) - bet UnboundLocalError: local variable 'money' referenced before assignment
    猜你喜欢
    • 2011-08-18
    • 2019-06-14
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    • 2017-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多