Always get printed value of “None”

后端 未结 4 387
小鲜肉
小鲜肉 2021-01-28 14:32

Alright so here is my code, I get the result I want but I keep getting the \"None\" value under it. How do I eliminate the \"None\" value?

n = input(\"What day o         


        
相关标签:
4条回答
  • 2021-01-28 14:49

    Change all the print statements in your days(n) function to return instead.

    0 讨论(0)
  • 2021-01-28 14:50

    days never returns anything, so it implicitly returns None. Change all of the print statements in days to return statements:

    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)
    
    0 讨论(0)
  • 2021-01-28 14:51

    This should do the trick:

    days = ["Sunday", "Monday", "Tuesday", "Wednesday",
            "Thursday", "Friday", "Saturday"]
    print days[(n+r) % 7]
    
    0 讨论(0)
  • 2021-01-28 15:03

    You print in function days and print result from function days. Because of function days returns nothing it prints None.

    0 讨论(0)
提交回复
热议问题