-1
import random
import time

def set_balance():

    print("Welcome to balance manager")
    print()
    print("1, Demo mode (10,000 play chips)")
    print("2, Real mode (PayPal, BTC deposit)")
    print()
    choice = int(input("Please enter your selection: "))

    if choice == 1:
        global balance 
        balance = 10000
        demomode = 1

    elif choice == 2:
        global balance

        balance = int(input("\nEnter the ammount to pay in £"))

def spin_wheel():

    print("\n\n\n\n\n\n\n\nLETS PLAY ROULETTE, YOUR BANK IS, £", balance)
    print()
    print("Red, 1")
    print("Black, 2")
    print("Please select your colour from the menu below")

    choice = int(input("\nOption selected "))

我在这里做错了什么?

4

2 回答 2

2

您还应该尝试balance在您的方法范围之外定义,在您的导入语句下方。

于 2013-06-28T14:06:31.013 回答
1

我想有一些代码丢失,但你不需要在 set_balance 中设置balance(或)全局。demomode

像这样称呼它

balance, demomode = set_balance()

set_balance如果你愿意,你仍然可以使用同名的 balance 作为局部变量,然后返回它

def set_balance():

    print("Welcome to balance manager")
    print()
    print("1, Demo mode (10,000 play chips)")
    print("2, Real mode (PayPal, BTC deposit)")
    print()
    choice = int(input("Please enter your selection: "))

    if choice == 1:
        balance = 10000
        demomode = True

    elif choice == 2:

        balance = int(input("\nEnter the ammount to pay in £"))
        demomode = False

    return balance, demomode
于 2013-06-28T14:08:41.267 回答