194k views
2 votes
2.13 LAB: Branches: Leap Year

A year in the modern Gregorian Calendar consists of 365 days. In reality the earth takes longer to rotate around the sun. To account for the
difference in time every 4 years a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The
requirements for a given year to be a leap year are:
1) The year must be divisible by 4
2) If the year is a century year (1700 1800. etc.), the year must be evenly divisible by 400
Some example leap years are 600712 and 2016
Wirte a program that takes n a year and determines whether that year is a leap year.
Exif the inputs
1712

User Hsz
by
5.4k points

2 Answers

0 votes

Answer:

def is_leap_year(user_year):

if(user_year % 400 == 0):

return True

elif user_year % 100 == 0:

return False

elif user_year%4 == 0:

return True

else:

return False

if __name__ == '__main__':

user_year = int(input())

if is_leap_year(user_year):

print(user_year, "is a leap year.")

else:

print(user_year, "is not a leap year.")

Step-by-step explanation:

2.13 LAB: Branches: Leap Year A year in the modern Gregorian Calendar consists of-example-1
User Jrwren
by
4.5k points
5 votes

Answer:

The program in Python is as follows:

year = int(input("Enter a year: "))

print(year,end=" ")

if year % 4 == 0:

if year % 100 == 0:

if year % 400 == 0: print("is a leap year")

else: print("is not a leap year")

else: print("is a leap year")

else: print("is not a leap year")

Step-by-step explanation:

This gets input for year

year = int(input("Enter a year: "))

This prints year, followed by a blank

print(year,end=" ")

If year is divisible by 4

if year % 4 == 0:

If yes, check if year is divisible by 100

if year % 100 == 0:

If yes, check if year is divisible by 400; print leap year if true

if year % 400 == 0: print("is a leap year")

print not leap year if year is not divisible by 400

else: print("is not a leap year")

print leap year if year is not divisible by 100

else: print("is a leap year")

print leap year if year is not divisible by 4

else: print("is not a leap year")

User Amad
by
5.7k points