【发布时间】:2019-02-23 03:04:47
【问题描述】:
我的代码:
reask = input('So do you want me to solve a quadratic equation? Last chance or I will close and you have to start me again! Make sure you type \'yes\' or \'no\': ')
reask = reask.lower
if reask == 'yes':
print ('Great!')
else:
print ('See ya!')
raise SystemExit
当用户输入'yes' 时,程序会将其解释为其他内容并最终打印出'See ya!',然后关闭程序。它应该打印'Great!'。有什么问题?
【问题讨论】:
-
你有一个错字。
reask = reask.lower应该是reask = reask.lower()。您将reask设置为函数lower,而不是调用函数。 -
reask.lower返回函数对象,而不是您想要的结果 -
天哪,我什至都懒得去找那个。谢谢!
-
为什么需要括号?为什么括号里什么都没有?
-
需要括号来区分函数本身,它是一个像任何其他对象一样的对象,以及对函数的调用。括号中没有任何内容,因为这个特定的函数没有参数。