(Find the number of days in a month) Write a program that prompts the user to enter the month and year and displays the number of days in the month. For example, if the user entered month 2 and year 2000, the program should display that February 2000 has 29 days. If the user entered month 3 and year 2005, the program should display that March 2005 has 31 days.
#Prompt the user to give input
number_Of_DaysInMonth = 0
MonthOfName = "Unknown"
print("Input a month number: ")
month = int(input())
print("Input a year: ")
year = int(input())
#Initialize dictionary
switcher={1:"January",
2:"February",
3: "March",
4:"April",
5:"May",
6:"June",
7:"July",
8: "August",
9:"September",
10: "October",
11:"November",
12:"December"}
#Display Results
if(switcher.get(month)=="January"):
print("January {} has 31 days".format(year))
elif(switcher.get(month)=="February"):
if((year % 400 == 0) or ((year % 4 == 0) and (year % 100!=0))):
print("Febrauary {} has 29 days".format(year))
else:
print("February {} has 28 days ".format(year))
elif(switcher.get(month)=="March"):
print("March {} has 31 days".format(year))
elif(switcher.get(month)=="April"):
print("April {} has 30 days".format(year))
elif(switcher.get(month)=="May"):
print("May {} has 31 days".format(year))
elif(switcher.get(month)=="June"):
print("June {} has 30 days".format(year))
elif(switcher.get(month)=="July"):
print("July {} has 31 days".format(year))
elif(switcher.get(month)=="August"):
print("August {} has 31 days".format(year))
elif(switcher.get(month)=="September"):
print("september {} has 30 days".format(year))
elif(switcher.get(month)=="October"):
print("October {} has 31 days".format(year))
elif(switcher.get(month)=="November"):
print("November {} has 30 days".format(year))
elif(switcher.get(month)=="December"):
print("December {} has 31 days".format(year))
Output:
Input a month number:
12
Input a year:
7889
December 7889 has 31 days