我的方程式似乎不起作用,但看起来是正确的



我是一个业余的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()

条件中的名称需要与您初始化按钮时使用的名称匹配:

改变:

if name == 'InsertBet':

自:

if name == 'Insert Bet':

你的问题之一在这两行:

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

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

另一个问题,正如blhsing的答案所指出的,是你正在检查"Insert Bet"按钮是否被称为"InsertBet",而不是;因此你根本没有运行按钮按下代码!

if name == 'InsertBet':

应该是

if name == 'Insert Bet':

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

最新更新