Home > Enterprise >  I'm on a project trying to create a leap year generator. Every year works besides the years wit
I'm on a project trying to create a leap year generator. Every year works besides the years wit

Time:05-07

Any time I type the years that end with 16 or 20, example: 2016 or 3020, it just ends. The code I am using is below, any help would be much appreciated. Thank you.

year = int(input("Year??? ")

if year % 4 == 0:
    if year % 100 == 0:
        if year % 400 == 0:
            print("Leap year.")
        elif year != 0:
            print("Not leap year.")
else:
    print("Not leap year.")

CodePudding user response:

Try something like this:

year = int(input("Year???"))
if (year@0 == 0):
          print("Not a leap year")
elif (year0 == 0): # elif is preferable to nested if in most cases
          print("Not a leap year")
elif (year%4 == 0):
          print("This is a leap year!")
else:
          print("This is not a leap year")

CodePudding user response:

year = int(input("Year???"))

if not year % 4 and (year % 100 or not year % 400):
    print("This is a leap year!")
else:
    print("Not a leap year")
  • Related