Python 类型错误:'&燃气轮机';在';功能';和';int';?
为什么我会出现错误请解释一切从上到下基本上都在运行,直到它到达该函数,然后它给了我一个错误,我正试图找出这个错误,因为我所有的if-an-elif和else语句似乎都正常运行Python 类型错误:'&燃气轮机';在';功能';和';int';?,python,function,if-statement,typeerror,Python,Function,If Statement,Typeerror,为什么我会出现错误请解释一切从上到下基本上都在运行,直到它到达该函数,然后它给了我一个错误,我正试图找出这个错误,因为我所有的if-an-elif和else语句似乎都正常运行 **Getting error but confused why everything seems to be in place as it should be?** 这里就是我得到错误的地方 import random import emoji def decor(write): def wrap():
**Getting error but confused why everything seems to be in place as it should be?**
这里就是我得到错误的地方
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()
这是错误信息
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()
>回溯(最近一次调用上次):文件
>“/private/var/mobile/Containers/Shared/AppGroup/3EBFD0C8-D5AE-4513-B2E3-6C38570AE9F0/Pythonista3/Documents/site-packages-3/decision maker.py”,第60行
>决策者()文件“/private/var/mobile/Containers/Shared/AppGroup/3EBFD0C8-D5AE-4513-B2E3-6C38570AE9F0/Pythonista3/Documents/site-packages-3/Decision maker.py”,第49行,决策者
>如果x>4:TypeError:“function”和“int”实例之间不支持“>”
问题在于:
> 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
您正在传递函数,而不是函数的结果。相反,请尝试:
x = lambda x: x*2 + 1
if x > 4:
其中,值是要传递到函数中的任何内容。通过编写“lambda x:”您正在使用参数“x”创建一个匿名函数。
x
在这里是一个函数,您没有向它输入任何值。另外,要避免使用与lambda函数相同的变量名,这会让人感到困惑。老实说,我只是加入了lambda函数,因为我在@ZWangPost@traceback消息中多练习了一点。我们需要错误和失败行的确切文本。没有lambda函数,您仍然没有给出x
任何变量。尝试执行类似于x(1)
的操作,错误将不会显示