I'm taking the 100 Days of Code (Python) taught by Angela Yu on Udemy. There have been a few other questions revolving around this lesson but I can't find one who came up with my specific question so I do apologize if it's out there somewhere.
The course is asking us to check whether or not a year is a leap year using the below flow chart:
If not cleanly divisible by 4 - Not a leap year.
If is cleanly divisible by 4 but not cleanly divisible by 100 - A leap year
If is cleanly divisible by 4, and by 100, but not cleanly divisible by 400 - Not a leap year
If is cleanly divisible by 4, is cleanly divisible by 100 and if is cleanly divisible by 400 - Leap year
The code I came up with does generate the desired outputs and passes the checks required to finish the lesson. I've tested it against a good two dozen years and it's correctly identified whether or not the year was a leap year each time. I'm not getting any syntax errors either. Most of my solutions to the lessons so far have had small variations but this one feels moreso than any of the rest and it's making me question its validity.
The point of the lesson is to get acclimated with if/elif and else statements, so I'm not trying to optimize it or use any more advanced/efficient/shorter keywords. The instructor provides their own solution but does specify there are other ways to go about it.
Is mine just structured poorly? Is there a scenario where it wouldn't work? Again, limiting it to only if/elif and else keywords is very much intentional.
My code:
year = int(input())
if year % 4 != 0:
print ("Not leap year")
elif year % 100 != 0:
print ("Leap year")
elif year % 400 !=0:
print ("Not leap year")
else:
print ("Leap year")
Instructor:
year = int(input())
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
print("Leap year")
else:
print("Not leap year")
else:
print("Leap year")
else:
print("Not leap year")