Problem: Write a Python module (a text file containing valid Python code). This file will contain the following.
Definition of a list containing strings which are in turn integers. These integers represent years, which will be used as inputs to the next item in the file
Definition of a function named isLeap. This function must accept a string containing an integer that will be interpreted by this function as a year. If the year is prior to the introduction of the Gregorian calendar, it will print “Not Gregorian.” If the year is a Gregorian year and a leap year, it will print “Leap year!”. If the year is a Gregorian year but not a leap year, it will print “Not a leap year!”.
A for loop that will call isLeap with each of the year strings in the list of year strings defined above.
#Python program that check the list of years stored in years as string
#if the year is not gregorian year, print ,'Not Gregorian'
#if the year is gregorian year and it is leap year then print , 'leap year'
#if the year is gregorian year and it is not leap year then print , 'not a leap year'
#leapyear.py
def main():
#create a list of years as strings
years = ['1581', '2000', '2005','1500']
#for loop to to check if year values
for year in years:
print(year,'is ',end=' ')
#calling isLeap method
isLeap(year)
#The method isLeap takes a year value as string and convert the year to integer type
#if the year is not gregorian year, print ,'Not Gregorian'
#if the year is gregorian year and it is leap year then print , 'leap year'
#if the year is gregorian year and it is not leap year then print , 'not a leap year'
def isLeap(y):
year = int(y)
if year < 1582:
print('Not Gregorian')
elif (year >=1582):
if(year % 4 == 0 and (year % 100 != 0) or (year % 400 == 0)):
print('Leap year!')
else:
print('Not a leap year!')
#calling main method
main()
Sample Output:
1581 is Not
Gregorian
2000 is Leap year!
2005 is Not a leap year!
1500 is Not Gregorian
Get Answers For Free
Most questions answered within 1 hours.