0

Why won’t the code work when 2000 plugged in help please it’s for the leap year checker

year = int(input()) if (year % 4): if (year % 100): if(year % 400): print('leap year') else: print("Leap year") else: print('Not a leap year')

5th Feb 2021, 2:34 AM
kole roper
kole roper - avatar
6 Antworten
+ 5
It is because when you divide 2000 by 4 the remender will be 0 , and 0 is considered as False , if you want that condition be True then you can apply this if (year % 4 == 0) or if (not year % 4) , it will give you True in leap year! Because if 0 reminder will come then 0==0 will be True and not 0 will be True https://code.sololearn.com/cssJxMhziikv/?ref=app See this code , All the best!
5th Feb 2021, 2:57 AM
Abhiyantā
Abhiyantā - avatar
+ 1
if year%400==0 or (year%4==0 and year%100!=0) : #leap year
5th Feb 2021, 3:06 AM
Angelo
Angelo - avatar
+ 1
thank you
5th Feb 2021, 3:41 AM
kole roper
kole roper - avatar
+ 1
sorry it has me set it up so the iser can plug a number in and find out if its leap year or not
5th Feb 2021, 4:34 AM
kole roper
kole roper - avatar
+ 1
so how do infix it so it will work with any year
5th Feb 2021, 4:40 AM
kole roper
kole roper - avatar
+ 1
Just write, int(input()) where I have written 2000
5th Feb 2021, 5:48 AM
Abhiyantā
Abhiyantā - avatar