Selena Cruz
Selena Cruz

Reputation: 21

TypeError: '>' not supported between instances of 'function' and 'function

def get_bank_balance(): #prompt for an intial bank balance
    balance = int(input("Enter an initial bank balance (dollars): "))
    return balance


def add_to_bank_balance(balance):   #prompt for amount to add to balance
    wager = int(input("Enter a wager (dollars): "))
    return wager


def get_wager_amount():     #prompt for a wager on a particular roll
    wager = add_to_bank_balance
    return wager


def is_valid_wager_amount(wager, balance):      # checks that wager is less than or equal to balance
    if wager < balance:
        return is_valid_wager_amount(wager, balance)

def main(): 
    # plays the game 
    display_game_rules() 
    get_bank_balance() 
    add_to_bank_balance(balance) 
    get_wager_amount() 
    is_valid_wager_amount(wager, balance)

Upvotes: 1

Views: 5827

Answers (1)

Matt Messersmith
Matt Messersmith

Reputation: 13747

The interpreter is telling you exactly what the problem is. You can't compare two function objects using <. Your code has some extraneous issues I don't want to get in to, so let's consider a more minimal example of how you can get this error and how you can fix it.

Here's how you could get the TypeError you're getting:

def func1():
    return 1

def func2():
    return 2

if func1 < func2:
    print("All is well. 1 is less than 2.")

Slap this code into a file called test.py and run it in your shell:

PS C:\Users\matt\repos\kata\stack> python test.py
Traceback (most recent call last):
  File "test.py", line 7, in <module>
    if func1 < func2:
TypeError: '<' not supported between instances of 'function' and 'function'

This is the exact error you (somehow) got (although you're not showing your full code, because the code you've shown would cause a different error upon invoking main()).

The problem: func1 is a function (and so is func2). In order to call it, you have to say func1().

The fix:

# func1 -> func1() and func2 -> func2().
if func1() < func2():
    print("All is well. 1 is less than 2.")

then if you run it again with this change, you'll get the expected result:

PS C:\Users\matt\repos\kata\stack> python test.py
All is well. 1 is less than 2.

You may want to take a step back and read more about variables, functions, and Python fundamentals before writing your bank application.

HTH.

Upvotes: 3

Related Questions