Question

In: Computer Science

Create a python program to determine which years are leap years (see key information at the...

Create a python program to determine which years are leap years (see key information at the bottom). Note: Do not use any lists.

1. Define a function that takes a parameter (year) and verifies if the parameter year is a leap year. If it is a leap year, the function returns True. Else, it returns False. Note: the function should not print anything.

2. Using the function, check if each of the years from 2000 to 2200 (both inclusive) is a leap year.

3. Output all the leap years between 2000 and 2200 in a single line

4. Program should end by printing the number of leap years found, with a short message.

Key information to determine if a given year is a leap year or not:

1. Determine whether the year is divisible by 100. If it is, then the year is a leap year if and only if the year is also divisible by 400. For example, 2000 is a leap year, but 2100 is not.

2. If the year is NOT divisible by 100, then the year is a leap year if and only if it is divisible by four. For example, 2008 is a leap year, but 2009 is not

Solutions

Expert Solution

Python code:

#defining function to print leap year
def leap_year(year):
#checking if the year is divisible by 4
if(year%4==0):
#checking if the year is divisible by 100
if(year%100==0):
#checking if the year is divisible by 400
if(year%400==0):
#returning True
return True
else:
#returning False
return False
else:
#returning True
return True
else:
#returning False
return False
#count to keep track of number of leap years
count=0
#looping from 2000 to 2201
for i in range(2000,2201):
#checking if the year is leap year
if(leap_year(i)):
#incrementing count
count+=1
#printing year
print(i,end=" ")
#printing Number of leap years found
print("\nNumber of leap years found:",count)


Screenshot:


Output:


Related Solutions

Create this on Python Write a program that asks for three numbers. Check first to see...
Create this on Python Write a program that asks for three numbers. Check first to see that all numbers are different. If they’re not different, then exit the program. Otherwise, display the largest number of the three. Outputs: - Enter the first number: 4 - Enter the second number: 78 - Enter the third number: 8 (The largest number is 78.) Tasks - Complete the algorithm manually without using any built-in functions to find the largest number on list. -...
Utilize Python to create a key-value program similar to MapReduce on Hadoop. For this assignment, do...
Utilize Python to create a key-value program similar to MapReduce on Hadoop. For this assignment, do the following: Create a dictionary (also called an associative array) that contains at least 50 values. An example of a key may be state and value as capital. Another example may be number in an alphabet and letter in an alphabet. Write a command that enumerates the contents of key-values in the dictionary. Write a command that lists all keys. Write a command that...
create a PYTHON program that will determine the cost per 3" serving for a giant sub...
create a PYTHON program that will determine the cost per 3" serving for a giant sub sandwich you will be ordering for a get-together with your friends. Within main(), get the input of the length in inches for the sub and the cost. Create function named numServings() that will receive the length in inches and return the number of servings. Each 3" is considered serving. Servings should be a whole number, so you will need to find a way to...
Write a program in assembly language that outputs the leap years between a beginning and an...
Write a program in assembly language that outputs the leap years between a beginning and an ending year. 1. Initialize $a0 and $a1 with the beginning and ending years. 2. Print out the leap years between 1970 and 2030. OUTPUT: From 1970 to 2030: 1972 … 2028
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program:...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program: Your program will create a username of your choice using a Kali Linux command "useradd -m mark", then set the password for that user using the Kali Linux Command "echo "mark:10101111" | chpasswd". Then you create a dictionary file using the Kali Linux command "crunch 8 8 01 > mylist.txt" Your python script should crack the password for that user and display on the...
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
In Python Create customer information system as follows: Python 3 Create customer information system as follows:...
In Python Create customer information system as follows: Python 3 Create customer information system as follows: Ask the user to enter name, phonenumber, email for each customer. Build a dictionary of dictionaries to hold 10 customers with each customer having a unique customer id. (random number generated) Take the keys of the above mentioned dictionary which are customer ids and make a list. Ask the use to enter a customer id and do a binary search to find if the...
>>python Question: Create program which acquires an integer in the range 1-17, and then outputs a...
>>python Question: Create program which acquires an integer in the range 1-17, and then outputs a times table from that acquired figure. Function should print times table and another function which acquires and returns the ranged integer. Therefore they are distinct functions. Specific details to include: You can also in the central area of the code script allocate a value which is returned aside a function to a variable.(For example table=yourchoiceinteger(1,17).) Therefore that table which is the variable will be...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will first enter a password, then enters the same password again; If the second input is the same as first one, the user successfully creates the password. Print “Well done.”; Otherwise, the user will be directed to repeat the whole process (go to step 1.)
Create a Python program that: Allows the user to enter a phrase or sentence. The program...
Create a Python program that: Allows the user to enter a phrase or sentence. The program should then take the phrase or sentence entered Separate out the individual words entered Each individual word should then be added to a list After all of the words have been place in a list Sort the contents of the list Display the contents of the sorted list with each individual word displayed on a separate line Display a message to the user indicating...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT