# Python Leap year problem (Code incuded)

The question is quite simple still I'm failing two tests; if year%4, year%100 and year%400 all ==0 it should print leap year otherwise if one of it gets false, it should print 'not a leap year', still I'm failing two tests. I don't know what I'm missing here. year = int(input()) #your code goes here if year%4==0: if year%100==0: if year%400==0: print('Leap year') else: print('Not a leap year') else: print('Not a leap year') else: print('Not a leap year')

11/29/2021 12:34:44 PM

usman28 Answers

New Answery=int(input()) if y%400==0: print('leap year') elif y%100==0: print('not leap year') elif y%4==0: print('leap year') else: print('not leap year') This code 100% worked !!!

y=int(input()) if((y%4==0 and y%100!=0) or ( y%400==0)): print('leap year') else: print('not a leap year')

SoloProg , this code does not give correct results for checking if a year is a leap year. try your code with this years: (all are stated as leap years by your code) 1600 - leap year 1700 - NOT leap year 1800 - NOT leap year 1900 - NOT leap year 2000 - leap year 2004 - leap year BTW: it is not a good style to 'up-vote' his own posts.

HERE'S THE WAY IF A YEAR IS DIVISIBLE BY 4 IT BECOMES A LEAP YEAR UNLESS IT GETS DIVIDED BY 100 IF IT GETS DIVIDED BY 100 AFTER GETTING DIVIDED BY 4 THEN IT SHOULD ALSO BE DIVISIBLE 400 ELSE IT WILL NOT BECOME A LEAP YEAR SO if year%4==0: if year%100==0: if year%400==0: print('Leap year') else: print('Not a leap year') else: print('Leap year') #HERE else: print('Not a leap year')

Years divided by the number of 400 without residue are considered leap years. For example, 1200, 1600, 2000 years. Years divided into 100 without a remainder is not a leap year. For example: 1700, 1800, 1900 years. All that remains of them is a leap year, divided into 4 without residue. For example, 2004, 2008, 2011, 2016 .

Not all year where year%100==0 are leap year...year = int(input()) #your code goes here if year%400==0: print('Leap year') elif year%4==0 and year%100!=0: print('Leap year') else: print('Not a leap year')

list=[int(input())] for x in list: if(x%4==0): print("Leap year") elif(x%100==0): print("Leap year") elif(x%400==0): print("Leap year") else: print("Not a leap year")

The simplest if (year%400 == 0)or(year%4 == 0 and year %100 !=0): print("leap year") else: print("not a leap year")

I think this❤ code is right for Python💻 : If year%4=0; print("Leap year") Else : print("Not a leap year ")

Lothar I wrote "I think" because I did not check and it was a fast answer. Ty all for the suggestions. Also to get more information here is the link in the wiki. https://en.wikipedia.org/wiki/Leap_year

That is, all the years that are divided by the number 4 without a remainder are leap years, except for the years that end with two zeros. For example, 1300, 1400, 1500 years, etc.