 Python Leap year problem (Code incuded) | Sololearn: Learn to code for FREE!

+1

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')

+7

y=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 !!!

+3

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

+3

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.

+2

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')

+1

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 .

+1

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')

+1

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")

+1

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

0

Neither do we, let's see your code.

0

0

SoloProg That does not work

0

0

I know this code with python

0

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

0

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

0

Who is downvoting everyone?

-1

Conditions itself wrong for leap yr check

-1

Oh yeah, I misred the question. Thanks everyone.

-1

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.

-1

Please how do I represent Boolean in coding.