You failed to remember the ==0 or !=0 which will help comprehend the conditions better. You don't need to utilize them, yet then it can create turmoil keeping up the code.
def is_leap(year):
leap = False
if (year % 4 == 0) and (year % 100 != 0):
# Note that in your code the condition will be true if it is not..
leap = True
elif (year % 100 == 0) and (year % 400 != 0):
leap = False
elif (year % 400 == 0):
# For some reason here you had False twice
leap = True
else:
leap = False
return leap
You can also try this code (smaller version):
def is_leap(year):
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
Want to be a python expert? Come and join this python course