始终获得“无”的打印值

时间:2011-12-11 06:40:30

标签: python

好吧所以这是我的代码,我得到了我想要的结果,但我不断得到它下面的“无”值。如何消除“无”值?

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)

4 个答案:

答案 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)

您可以在功能日打印并从功能日打印结果。 由于函数天没有返回任何内容,它打印无。