[Type C] Python Revision Tour-1 – Chapter 1
Table of Contents
5. Write a program that asks the user the day number in the year in the range 2 to 365 and asks the first day of the year (e.g., Sunday, Monday, etc.), then the program should display the day on the day number that has been input.
day_number = int(input("Enter the day number in the year (2-365): "))
first_day = input("Enter the first day of the year (e.g., Sunday, Monday, etc.): ")
days_of_week = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
first_day_index = days_of_week.index(first_day.title())
day_index = (first_day_index + day_number - 1) % 7
print("Day number", day_number, "is", days_of_week[day_index])
Output
Enter the day number in the year (2-365): 150
Enter the first day of the year (e.g., Sunday, Monday, etc.): Monday
Day number 150 is Friday