首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError:'>‘函数’和'int‘的实例之间不支持?

TypeError:'>‘函数’和'int‘的实例之间不支持?
EN

Stack Overflow用户
提问于 2020-07-24 01:52:14
回答 1查看 978关注 0票数 1
代码语言:javascript
复制
**Getting error but confused why everything seems to be in place as it should be?**

,为什么我会得到错误,请解释一下,从上到下,所有的东西基本上都可以工作,直到它到达那个函数,然后,当它给我那个错误时,我正试图找出这个错误,因为我的所有if一个elif和else语句似乎都正常工作,正常工作。

代码语言:javascript
复制
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!")

这里是我得到错误的地方

代码语言:javascript
复制
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()

这里是错误

代码语言:javascript
复制
> 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
EN

回答 1

Stack Overflow用户

发布于 2020-07-24 01:59:34

问题在于:

代码语言:javascript
复制
x = lambda x: x*2 + 1
    if x > 4:

您正在传递您的函数,而不是您的函数的结果。相反,试着:

代码语言:javascript
复制
y = lambda x: x*2 + 1
    if y(value) > 4:

其中,是您想要传递到函数中的任何内容。通过编写"lambda:“,您将创建带有参数"x”的匿名函数。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63065596

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档