**Getting error but confused why everything seems to be in place as it should be?**,为什么我会得到错误,请解释一下,从上到下,所有的东西基本上都可以工作,直到它到达那个函数,然后,当它给我那个错误时,我正试图找出这个错误,因为我的所有if一个elif和else语句似乎都正常工作,正常工作。
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!")这里是我得到错误的地方
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()这里是错误
> 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发布于 2020-07-24 01:59:34
问题在于:
x = lambda x: x*2 + 1
if x > 4:您正在传递您的函数,而不是您的函数的结果。相反,试着:
y = lambda x: x*2 + 1
if y(value) > 4:其中,值是您想要传递到函数中的任何内容。通过编写"lambda:“,您将创建带有参数"x”的匿名函数。
https://stackoverflow.com/questions/63065596
复制相似问题