以下是我正在处理的项目的一些代码:
# Make sure that the_flying_circus() returns True
def the_flying_circus():
if (3 < 4) and (-10 > -20):# Start coding here!
print "Hey now!"# Don't forget to indent
# the code inside this block!
elif (-4 != -4):
print "Egad!"# Keep going here.
else:
return True # You'll want to add the else statement, too!
我不知道为什么这不满足返回True
的条件。有什么想法吗?在
此条件始终是
TRUE
:因此脚本将始终打印:
^{pr2}$Hey now!
。 不可能,代码将在任何一种情况下结束。在这些条件完全没有必要。您唯一能做的就是更改第一个条件(例如,使用一些变量,它将采用不同的值,这样就不会每次都是
TRUE
)好吧,3小于4。并且
^{pr2}$-10
大于-20
。所以这个表达式总是正确的。您的函数不执行return语句,因此返回None
。您的函数可以这样重写:这将返回
True
。否则,你总是会听到“嘿,现在!”因为您的if
条件总是True
。在如果您想在满足条件时返回
^{pr2}$True
,那么代码应该是相关问题 更多 >
编程相关推荐