In: Computer Science
python.Write a python program that prompts the user to enter the year and first day of the year, and displays the first day of each month in the year. For example, if the user entered the year 2020 and 3 for Wednesday, January 1, 2020, your program should display the following output:
January 1, 2020 is Wednesday
February 1, 2020 is Saturday ……
December 1, 2020 is Tuesday
Required program in python -->
days=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
year=int(input("Enter year"))
day=int(input("Enter day"))
if year % 4 == 0 and year % 100 != 0:
February=29
elif year % 100 == 0:
February=28
elif year % 400 ==0:
February=29
else:
February=28
print("January 1,",year," is ",days[day])
f=(day+31)%7
feb=days[f]
print("February 1,",year," is ",feb)
m=(f+February)%7
march=days[m]
print("March 1,",year," is ",march)
a=(m+31)%7
april=days[a]
print("April 1,",year," is ",april)
ma=(a+30)%7
may=days[ma]
print("May 1,",year," is ",may)
j=(ma+31)%7
june=days[j]
print("June 1,",year," is ",june)
ju=(j+30)%7
july=days[ju]
print("July 1,",year," is ",july)
au=(ju+31)%7
august=days[au]
print("August 1,",year," is ",august)
s=(au+31)%7
september=days[s]
print("September 1,",year," is ",september)
o=(s+30)%7
october=days[o]
print("October 1,",year," is ",october)
n=(o+31)%7
november=days[n]
print("November 1,",year," is ",november)
d=(n+30)%7
december=days[d]
print("December 1,",year," is ",december)
This program first take year as an input from user, then it checks whether a year is leap year or not, if it is leap year than it assigns February to 29, else to 28. Then we have a list from which we can count the days for each given month. We know jan has 31 days, march has 31 days, april has 30 days, like this, we find the remainder of days with 7, and then we access the list days[], and provide the output with suitable days.
o/p ->
Enter year2020
Enter day3
January 1, 2020 is Wednesday
February 1, 2020 is Saturday
March 1, 2020 is Sunday
April 1, 2020 is Wednesday
May 1, 2020 is Friday
June 1, 2020 is Monday
July 1, 2020 is Wednesday
August 1, 2020 is Saturday
September 1, 2020 is Tuesday
October 1, 2020 is Thursday
November 1, 2020 is Sunday
December 1, 2020 is Tuesday