我是一个业余的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()
条件中的名称需要与初始化按钮时使用的名称匹配:
更改:
致:
您的问题您的问题之一在于以下两行:这是检查
money
是否分别等于(int(money) - bet) + (bet * 2))
和int(money) - bet
。使用=
将money
设置为一个值另一个问题,正如blhsing's answer所指出的,是您正在检查
"Insert Bet"
按钮是否被称为"InsertBet"
,而不是;因此,您根本没有运行按钮按下代码应该是
第一个错误几乎总是相反!祝贺你对你的bug有创意:-p
相关问题 更多 >
编程相关推荐