好吧所以这是我的代码,我得到了我想要的结果,但我不断得到它下面的“无”值。如何消除“无”值?
n = input("What day of the week are you leaving?")
r = input("How many days will you be resting?")
def days(n):
if n == 0:
print "Sunday"
elif n == 1:
print "Monday"
elif n == 2:
print "Tuesday"
elif n == 3:
print "Wednesday"
elif n == 4:
print "Thrusday"
elif n == 5:
print "Friday"
elif n == 6:
print "Saturday"
elif n >= 7:
print days(n%7)
print days(n+r)
答案 0 :(得分:5)
这应该可以解决问题:
days = ["Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"]
print days[(n+r) % 7]
答案 1 :(得分:3)
days
永远不会返回任何内容,因此隐式返回None
。将print
中的所有days
语句更改为return
语句:
def days(n):
if n == 0:
return "Sunday"
elif n == 1:
return "Monday"
elif n == 2:
return "Tuesday"
elif n == 3:
return "Wednesday"
elif n == 4:
return "Thrusday"
elif n == 5:
return "Friday"
elif n == 6:
return "Saturday"
elif n >= 7:
return days(n % 7)
答案 2 :(得分:0)
将print
功能中的所有days(n)
语句改为return
。
答案 3 :(得分:0)
您可以在功能日打印并从功能日打印结果。 由于函数天没有返回任何内容,它打印无。