had just joined the community and picked up python3 quite recently. Am currently learning through the resource 'How To Think Like A Computer Scientist With Python3, 3rd Edition'. I was working through some exercises on chapter 4: functions and came across this problem: Problem in question
Currently my attempt at the problem is this(please forgive the formatting):
print('-----------Ex 2-----------')
days_of_week = ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')
def day_name(n):
if n >= 0 and n < 7:
return str(days_of_week[int(n)])
else:
return 'None'
print(day_name(1))
print('-----------Ex 3-----------')
def num_day(day_name):
for day in days_of_week:
if day == day_name:
return(days_of_week.index(day_name))
else:
return 'None'
print(num_day("Tuesday"))
For exercise 2 everything seems to be working fine, however with exercise 3 the function returns the index of the day together with 'None' as in here:Result
Greatly appreciate any explanation on why this occurs and how to remove the presence of the 'None'
Thanks!