[Type C]Q5. Write a program that asks the user the day number in a year in the range 2 to 365 and asks the first day of year-Sunday or Monday or Tuesday etc. Then the program should display the day on the day-number that has been input.

A function needs to be defined which takes the first day of the year and the day number in the specified range (2,365) and calculates mod 7 for the sum of passed parameters.

A list containing all days is created and the result of the mod operation is passed as an index to print a day from the list.

Program code:

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in

Output:

Year: 2020 
First day of the year (e.g. 'Monday'): Monday
Day number: 541 Invalid

In the above code, Year is taken input and a list containing all week days is created.

The first day of the year is then taken input, and then the day number.

If the day number is in the specified range as mentioned above, the year is a valid year, or else it is prompted to be invalid.

Basic python functionality is demonstrated in above program.

To view all the lessons in chapter 1: http://computertutor.in/class-12-computer-science/chapter-1/

To view entire class 12 computer science study material: http://computertutor.in/resources/

You cannot copy content of this page