如何在另一个函数中使用一个函数的返回值?

问题描述 投票:0回答:1

基本上,我已经创建了我的第一个函数并且它有一个返回值。我想在另一个函数中使用这个返回值。这是 PyCharm 中的 Python 代码,我是初学者,所以我对术语和所有内容都还很陌生。

这是我的第一个功能:

def deposit():  # amount he wants to bet with
    while True:
        amount = input("What would you like to deposit? $")
        if amount.isdigit():
            amount = int(amount)
            if amount > 0:
                break
            else:
                print("Amount must be greater than 0$")
        else:
            print("Please enter a number")

    return amount

这是我的第二个功能:

def get_bet():
    balance = amount   **HERE IS MY PROBLEM**
    while True:
        bet = input("What would you like to bet on each line? $")
        if bet.isdigit():
            bet = int(bet)
            if bet <= balance:
                if MIN_BET <= bet <= MAX_BET and bet <= balance:
                    break
                else:
                    print(f"Bet must be between ${MIN_BET} - ${MAX_BET} ")
            else:
                print(f"Bet must be within your balance of ${balance} ")
        else:
            print("Please enter a number")

    return bet

提前致谢

python function return
1个回答
0
投票

要从函数获取返回值,您必须执行该函数。 试试这个:

balance = deposit()

此行将执行函数 Deposit() 并将其返回值存储在变量余额中

© www.soinside.com 2019 - 2024. All rights reserved.