Why is year 1900 not returning False?

Question:

def is_leap_year(year):
    if (year%4==0 & (year%100!=0)) | (year%4==0 & year%100==0 & year%400==0):
        return True
    else:
        return False
print(is_leap_year(1900))

I would like for the argument (1900) to yield a False, since both sides of the or ( | ) statement fails to be true. What am I missing? This is written in Python.

Asked By: Labbsserts

||

Answers:

Try

def is_leap_year(year):
    if (year%4==0 and year%100!=0) or (year%4==0 and year%100==0 and year%400==0):
        return True
    else:
        return False
print(is_leap_year(1900))

& and | are bitwise AND and OR respectively, not logical operators.

Answered By: tkburis
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.