当我运行我的代码时,我一直看到“无”。为什么? 开始。
def love(n):
if n < 0 :
print "Why would it be negative?!"
if n == 0 :
print "well that is just hurtful"
if n == 1 :
print "I REALLY love you"
if n == 2 :
print "You make me smile at least once, each and every day"
if n == 3 :
print"you wouldn't believe how annoying it was to get this program to run properly! but it was worth it"
if n == 4 :
print "let's " + "shoot a little higher than that"
else:
print "I honestly can't see myself without you anymore"
print love(0)
print "Wanna try again? :D "
答案 0 :(得分:7)
love(0) # is all you need.
您不需要致电print love()
,因为您已经在love
内打印了对帐单。
您看到None
love
正在完成所有工作,并且没有返回任何内容。
此外,您需要在功能中使用if-elif-else
块,因为您希望一次只运行所有打印操作中的 one 。
if n < 0 :
print "Why would it be negative?!"
elif n == 0 :
print "well that is just hurtful"
elif n == 1 :
print "I REALLY love you"
elif n == 2 :
print "You make me smile at least once, each and every day"
elif n == 3 :
print"you wouldn't believe how annoying it was to get this program to run properly! but it was worth it"
elif n == 4 :
print "let's " + "shoot a little higher than that"
else:
print "I honestly can't see myself without you anymore"
虽然超出2
,打印一切都不会受到伤害;)
我的100 th 回答SO!耶!
答案 1 :(得分:1)
您的函数的默认返回值为None
,因此当您print
它时,它将打印None
。
只需在没有print
声明的情况下调用该函数。
或者,您可以使用print
替换函数中的所有return
语句,并将其转换为if-elif-else
块,因为它们都是互斥操作。然后,打印love(0)
实际上会打印出返回值。