Reputation: 49
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 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)
Upvotes: 0
Views: 120
Reputation: 33387
This should do the trick:
days = ["Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"]
print days[(n+r) % 7]
Upvotes: 5
Reputation: 4239
You print in function days and print result from function days. Because of function days returns nothing it prints None.
Upvotes: 0
Reputation: 50650
Change all the print
statements in your days(n)
function to return
instead.
Upvotes: 0
Reputation: 129001
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)
Upvotes: 3