【发布时间】:2020-11-13 20:22:27
【问题描述】:
**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
【问题讨论】:
-
x是这里的一个函数,你没有给它输入任何值。还要避免使用与 lambda 函数相同的变量名,这会让人感到困惑。 -
老实说只是加入了 Lambda 函数,因为我在练习它们@ZWang
-
发布回溯消息。我们想要错误和失败行的确切文本。
-
如果没有 lambda 函数,您仍然没有给
x任何变量。尝试执行x(1)之类的操作,错误不会显示。 -
你去@tdelaney
标签: python function if-statement typeerror