0

If task ??

Any idee , why is not functioning ? Check 1,2,7 are ok 3,4,5,6 are not :( """You need to make a program to take a year as input and output "Leap year" if it’s a leap year, and "Not a leap year", if it’s not. To check whether a year is a leap year or not, you need to check the following: 1) If the year is evenly divisible by 4, go to step 2. Otherwise, the year is NOT leap year. 2) If the year is evenly divisible by 100, go to step 3. Otherwise, the year is a leap year. 3) If the year is evenly divisible by 400, the year is a leap year. Otherwise, it is not a leap year. Sample Input 2000 Sample Output Leap year Use the modulo operator % to check if the year is evenly divisible by a number.""" year = int(input()) if year%4==0 : if year%100==0: if year%400==0 : print ("Leap year") else : print ("Not a leap year")

11th Feb 2021, 11:13 PM
Johny Bravo 123
Johny Bravo 123 - avatar
4 Answers
+ 7
Carefully read given steps. You have to use 'elif' statement or boolean operators. So your code needs to be year = int(input()) if year%4==0 and year %100!= 0 or year%400==0: print ("Leap year") else : print ("Not a leap year")
12th Feb 2021, 2:23 AM
Simba
Simba - avatar
+ 4
JĂĄnos BajĂĄri for your code only numbers divisible by 400 will be considered as leap year like 400,800,1200,1600 which is obviously wrong output . Maybe take a look at the following article to understand what years are considered as leap ones. https://docs.microsoft.com/en-us/office/troubleshoot/excel/determine-a-leap-year#:~:text=To%20eliminate%20this%20error%2C%20the,also%20evenly%20divisible%20by%20400.&text=This%20is%20because%20they%20are,100%20but%20not%20by%20400.&text=This%20is%20because%20they%20are%20evenly%20divisible%20by%20both%20100%20and%20400.
11th Feb 2021, 11:34 PM
Abhay
Abhay - avatar
+ 4
János Bajári You can specify a relevant programming language name e.g. Python in the thread's tags (where you wrote a question mark ? up there ☝)
12th Feb 2021, 1:14 AM
Ipang
+ 1
thx
12th Feb 2021, 8:44 AM
Johny Bravo 123
Johny Bravo 123 - avatar