Time Table Planning

Time Table Planning

A famous matriculation school in the city conducts a computer based activity for their students.  In this activity, when the students enter :

  1. An year –  against which they type Leap Year / Not Leap Year
  2. The month number –  against which they type the name of the corresponding month and the number of days in that month.   

Refer the sample input and output statements for more details.

As a Python programmer, you have to create a Python module named ‘date.py’ with the following functionalities which will help the staff members for cross verifying the answers submitted by children against the right answers.   The ‘date.py’ module  should contains the functions given below:

1.    is_leap(year) – to check if the given year is leap year or not
2.    month_name(no) – that returns the name of the month, on entering the month’s number
3.    days_in_month(month,year) – that returns the number of days in a month

Sample input 1:

Enter year as 4 digits (e.g: 2002):2016

Enter month number:1

Sample output 1:

Year:  Leap Year

Month Name:  January

Days in month:  31
Sample input 2:

Enter year as 4 digits (e.g: 2002):2018

Enter month number:2

Sample output 2:

Year: Not Leap Year

Month Name: February

Days in month: 28

Code :-


import calendar
def is_leap(year):
    return ( year%4==0 and year % 100!=0 )or year % 400 == 0
def month_name(no):
    return calendar.month_name[no]
def days_in_month(month,year):
    return calendar.monthrange(year,month)[1]


from Dates import *
year=int(input("Enter year as 4 digits (e.g: 2002):"))
month=int(input("Enter month number:"))
print("Year:", ("Leap Year") if is_leap(year) else "Not Leap Year")
print("Month Name: ",month_name(month))
print("Days in month: ",days_in_month(month,year))

Leave a Comment

Your email address will not be published. Required fields are marked *