Python 3.7.4: The current calendar, called the Gregorian calendar, was introduced in 1582. Every year divisible by four was created to be a leap year, with the exception of the years ending in 00 (that is, those divisible by 100) and not divisible by 400. For instance, the years 1600 and 2000 are leap years, but 1700, 1800, and 1900 are not. Write a program that requests a year as input and states whether it is a leap year. We need to run this as many times as the user wants to check for leap years. --------------------------- Below is my original program. I need to change it so that it now has a main() function plus three more functions. Do I convert the while loop to an if loop? The instructor said that it was a bad habit to include "break" in loops, so I was able to eliminate that. I just don't know how I can get that many functions out of this program. ''' Determine if a given year is a leap year, running as many times as the user wants to check for leap years''' # instructionsprint('This program determines if a given year is a leap year.')year= input("Enter year or stop to exit: ") # processwhile year.upper() != "STOP": # provides a break to the loop if int(year) % 400 == 0: # check if the year entered by user is a leap year or not print(year,"is a leap year") elif int(year) % 100 == 0: print(year, "is not a leap year") elif int(year)%4 == 0: print(year,"is a leap year") # output else: print(year, "is not a leap year") year= input("Enter year or stop to exit: ") print("Thank you.")
Python 3.7.4:
The current calendar, called the Gregorian calendar, was introduced in 1582. Every year divisible by four was created to be a leap year, with the exception of the years ending in 00 (that is, those divisible by 100) and not divisible by 400. For instance, the years 1600 and 2000 are leap years, but 1700, 1800, and 1900 are not. Write a
---------------------------
Below is my original program. I need to change it so that it now has a main() function plus three more functions. Do I convert the while loop to an if loop? The instructor said that it was a bad habit to include "break" in loops, so I was able to eliminate that. I just don't know how I can get that many functions out of this program.
''' Determine if a given year is a leap year, running as many times as the user wants to check for leap years'''
# instructions
print('This program determines if a given year is a leap year.')
year= input("Enter year or stop to exit: ")
# process
while year.upper() != "STOP": # provides a break to the loop
if int(year) % 400 == 0: # check if the year entered by user is a leap year or not
print(year,"is a leap year")
elif int(year) % 100 == 0:
print(year, "is not a leap year")
elif int(year)%4 == 0:
print(year,"is a leap year")
# output
else:
print(year, "is not a leap year")
year= input("Enter year or stop to exit: ")
print("Thank you.")
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images