In: Computer Science
Do Programming Exercise 1 (Day of the Week) – Page 151 Output should look like this.. >>> =RESTART: C:/Users/gamada/AppData/Local/Programs/python/python36/week/py= what is your name? gamada Enter a number (1-7) for the day of the week: 3 you selected 3 which is wednesday
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
#code
#creating a list that contain names of all 7 days
days=['monday','tuesday','wednesday','thursday','friday','saturday','sunday']
#reading name
name=input('what is your name? ')
#reading day of week (converting from string to int)
day=int(input('Enter a number (1-7) for the day of the
week: '))
#validating day
if day<1 or day>7:
#invalid
print('Invalid day')
else:
#valid, displaying day and name of day,
which is stored at
#index day-1 (list indices start from 0) in days
list
print('you selected
'+str(day)+' which is '+days[day-1])
#output
what is your name? oliver
Enter a number (1-7) for the day of the week: 3
you selected 3 which is wednesday