Ralph9496
Ralph9496

Reputation: 19

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

**Getting error but confused why everything seems to be in place as it should be?**

why Am I getting the error please explain everything works from top to bottom basically till it hits that function and then that’s when it gives me that error that I am trying to figure out Because all my if an elif and else statement seems to be in order and working properly

import random
import emoji


def decor(write):
    def wrap():
        print(“Choose a decision!” + “\U0001F604")
        write()
        print("-Testing mode-")
    return wrap()
    
def print_text():
    print("mini project")
decorated = decor(print_text)
print("")



decision = input("please enter decision: " + "")

if decision == ("Right answer"):
    decision = input("I will go to work today!: "+"\U0001F600")
    
    
elif decision ==("Wrong answer"):
    decision = input("Will not go to work today: "+ "\U0001F612")
    
    
else:
    print("Invalid answer try again!")
    

    
if decision == ("Wrong answer"):
     decision = input("But in a bad mood: ")
   
   
elif decision ==("Right answer"):
    decision = input("Your check will come out bigger cause you put in more hours: ")
    print(decision)

    
else:
    print("Invalid answer try again!")
    
    

Here is where I am getting the error

def Decision_maker():
    x = lambda x: x*2 + 1
    if x > 4:
        decision = ("Right answer")
        decision == input("You got a raise!")
        
if decision == ("Wrong answer"):
    decision = input("You got fired: ")
            
        
        

    
Decision_maker()

Here is the error

> Traceback (most recent call last):   File
> "/private/var/mobile/Containers/Shared/AppGroup/3EBFD0C8-D5AE-4513-B2E3-6C38570AE9F0/Pythonista3/Documents/site-packages-3/decision maker.py", line 60, in <module>
>     Decision_maker()   File "/private/var/mobile/Containers/Shared/AppGroup/3EBFD0C8-D5AE-4513-B2E3-6C38570AE9F0/Pythonista3/Documents/site-packages-3/decision maker.py", line 49, in Decision_maker
>     if x > 4: TypeError: '>' not supported between instances of 'function' and 'int

    

    

Upvotes: 1

Views: 1777

Answers (1)

TheWriter
TheWriter

Reputation: 256

The problem is here:

x = lambda x: x*2 + 1
    if x > 4:

You're passing your function rather than the result of your function. Instead try:

y = lambda x: x*2 + 1
    if y(value) > 4:

Where value is whatever you want to pass into your function. By writing "lambda x:" you're creating an anonymous function with the argument "x".

Upvotes: 1

Related Questions