Python Program to count the number of days in a given month of a year
Number of days in a given month of a given year
Number of days in any month of a year can vary specifically in February as the cycle of leap year repeats in every 4 years when the year is leap February gives the count to 29 days but the when the year is not leap it gives count to 28 days and so no of days in a year varies from 365 to 366.
Rather than February every month gives the count of 30 or 31 days in any case whether the year is a leap or not.
- Step 1:- Start.
- Step 2:- Take user inputs like month and year.
- Step 3:- Check if the given month is February.
- Step 4:- If True Check if the year is a year leap or not.
- Step 5:- If year is a leap year Print 29 Days, Else Print 28 Days.
- Step 6:- If Condition in Step 3 is False Check the month.
- Step 7:- Print the number of days assigned to specific Month.
- Step 8:- End.
Python Program for number of days
#take user inputs for Month and year in integer Month = int(input('Enter the Month :')) Year = int(input('Enter the Year :')) #Check condition for Month and leap year if(Month == 2 and (Year%4 == 0) or ((Year%100 == 0) and (Year%400 == 0))): #if condition is TRUE print('Number of days is 29') #if False check for other conditions elif(Month == 2): print('Number of days is 28') elif(Month == 1 or Month == 3 or Month == 5 or Month == 7 or Month == 8 or Month == 10 or Month == 12): print('Number of days is 31') else: print('Number of days is 30')
Enter the Month :2
Enter the Year :2012
Number of days is 29