10.6k views
0 votes
A leap year in the Gregorian calendar system is a year that's divisible by 4 but not by 100, unless it is also divisible by 400. For example, 1896, 1904, and 2000 were leap years but 1900 was not. Write a function that takes in a year as input and prints whether it's a leap year (or not). In the program, ask the user to input a year and then call the function to determine whether the input year is a leap year or not. Display the result to the user.

2 Answers

3 votes

Answer: Your friend is writing a program that will allow the user to input a year and then print “LEAP!” if that year is a leap year or print “not a leap year” if it is not. However, the program isn’t working properly, and your friend asked you for help in debugging.

Before you take a look at the program, you should know these rules for leap years:

A year is a leap year if it can be divided by 400 without a remainder.

A year is a leap year if it can be divided by 4 without a remainder, unless it can also be divided by 100 without a remainder; if that is the case, it is not a leap year.

All other years are not leap years.

Here is your friend’s code:

year=int(input()

if year%400=0:

print("LEAP!")

else:

print(not a leap year")

elseif year%4==0 and year%100!=0

print(“not a leap year")

Step-by-step explanation:

User Olayemi
by
5.0k points
2 votes

Answer:

def leap_year(year):

return int(year) % 4 == 0 and (int(year) % 100 != 0 or int(year) % 400 == 0)

Step-by-step explanation:

User Milad R
by
4.9k points