Introduction
Days in month is a python based programming project. This program how many days are there in a month.
Days in month is a python version 3.9 based program. It is a program for checking the number of days in a month in a year. It is a simple program with some lines of code. The program asks the user to enter a random year and month which you want to know how many days.
The program provides the result of that specific month. You must use integers while checking the days. The program uses leap year program for finding the days in February. The program uses functions, for loop, and if else control statement. A function needs to be called to use this program. See the code and output below.
def is_leap(year): if year % 4 == 0: if year % 100 == 0: if year % 400 == 0: return True else: return False else: return True else: return False def days_in_month(year, month): month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] if is_leap(year) and month == 2: if month > 12 or month < 1: return "invalid month" return 29 return month_days[month - 1] year = int(input("Enter a year: ")) month = int(input("Enter a month: ")) days = days_in_month(year, month) print(f"There are {days} days")
Output