Question

Problem: Write a Python module (a text file containing valid Python code). This file will contain...

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.

Homework Answers

Answer #1
#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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I need python code for this. Write a program that inputs a text file. The program...
I need python code for this. Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order. Uppercase words should take precedence over lowercase words. For example, 'Z' comes before 'a'. The input file can contain one or more sentences, or be a multiline list of words. An example input file is shown below: example.txt the quick brown fox jumps over the lazy dog An example of the program's output...
C++ code This project uses the text file (patient.dat) containing the following data: Patient number      ...
C++ code This project uses the text file (patient.dat) containing the following data: Patient number       integer Patient last name    string Patient surgery        string Patient age               integer Create a menu driven C++ project containing a user defined class with public functions that do the following: Read in all data into a linked list Display a menu for the user selections Add another set of patient data Print all data in the linked list Print all patients who...
Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...
Please answer this question using python programming only and provide a screen short for the code....
Please answer this question using python programming only and provide a screen short for the code. Reading: P4E 7; Tut 7.2, 7.2.1 Upload an original Python script that satisfies the following criteria: It has at least two functionsFunction 1: This function has one parameter, a string containing the path to an existing text file that will be read by your function Using a with statement, the function opens the file indicated by the parameter for reading The function counts the...
[Python] Write a function named "total_population" that takes a string then a list as parameters where...
[Python] Write a function named "total_population" that takes a string then a list as parameters where the string represents the name of a CSV file containing city data in the format "CountryCode,CityName,Region,Population,Latitude,Longitude" and the second parameter is a list where each element is itself a list containing 3 strings as elements representing the CountryCode, CityName, and Region in this order. Return the total population of all cities in the list. Note that the city must match the country, name, and...
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first,...
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first, third, fifth (and so on) characters of the strings, with each character both preceded and followed by the ^ symbol, and with a newline appearing after the last ^ symbol. The function returns no value; its goal is to print its output, but not to return it. Q2) Write a Python function called lines_of_code that takes a Path object as a parameter, which is...
Module 4 Assignment 1: Pseudocode & Python with Variable Scope Overview Module 4 Assignment 1 features...
Module 4 Assignment 1: Pseudocode & Python with Variable Scope Overview Module 4 Assignment 1 features the design of a calculator program using pseudocode and a Python program that uses a list and functions with variable scope to add, subtract, multiply, and divide. Open the M4Lab1ii.py program in IDLE and save it as M4Lab1ii.py with your initials instead of ii. Each lab asks you to write pseudocode that plans the program’s logic before you write the program in Python and...
Please create a python module named homework.py and implement the functions outlined below. Below you will...
Please create a python module named homework.py and implement the functions outlined below. Below you will find an explanation for each function you need to implement. When you are done please upload the file homework.py to Grader Than. Please get started as soon as possible on this assignment. This assignment has many problems, it may take you longer than normal to complete this assignment. This assignment is supposed to test you on your understanding of reading and writing to a...
python problem: ( use a loop to read each character from the string and insert into...
python problem: ( use a loop to read each character from the string and insert into the stack) 1. The function main a5.py continually asks the user for a string, and calls isPalindrome to check whether each string is a palindrome. A palindrome is a word or sequence that reads the same backward as forward, e.g., noon, madam or nurses run. 2. Your function must ignore spaces: when the user enters 'nurses run', the function returns True, to indicate that...
Assignment 2 Programming Language: Python 2 Preface: Create a new python file with a name of...
Assignment 2 Programming Language: Python 2 Preface: Create a new python file with a name of your choosing (ex: “assignment2.py”). At the top of the file paste the following: import numpy as np import random class Base_Obstacle_Map(object):     def __init__(self, length, width):         self.map = np.zeros((length, width), dtype=np.uint8)     def add_obstacle(self, x, y):         self.map[x, y] = 1     def remove_obstacle(self, x, y):         self.map[x, y] = 0     def display_map(self):         try:             import matplotlib.pyplot as plt             plt.imshow(self.map)...