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

2024-09-29 22:22:00 发布

您现在位置:Python中文网/ 问答频道 /正文

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

Tags: theimportguirandomarraywinintinsert
2条回答

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

更改:

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's answer所指出的,是您正在检查"Insert Bet"按钮是否被称为"InsertBet",而不是;因此,您根本没有运行按钮按下代码

if name == 'InsertBet':

应该是

if name == 'Insert Bet':

第一个错误几乎总是相反!祝贺你对你的bug有创意:-p

相关问题 更多 >

    热门问题