Don't know where I make mistakes in my coding | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

Don't know where I make mistakes in my coding

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. https://code.sololearn.com/cxbNlq939Zly/?ref=app

12th Aug 2021, 7:05 AM
Thasneem Mohamed
Thasneem Mohamed - avatar
13 Respuestas
+ 10
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ Your formula is 🆗 & works but is overloaded cose every year dividend by 4️⃣0️⃣0️⃣ is also dividend by4️⃣ & 1️⃣0️⃣0️⃣ & of course it's the leap year‼️ Short formula for leap year: y%4==0 and y%100 or y%400==0 https://code.sololearn.com/c0GLoPQmJ3tb/?ref=app
12th Aug 2021, 12:08 PM
Janusz Bujak 🇵🇱 🇺🇦
Janusz Bujak 🇵🇱 🇺🇦 - avatar
+ 3
No bro my hidden case 1 and 7 shows it is wrong
12th Aug 2021, 7:10 AM
Thasneem Mohamed
Thasneem Mohamed - avatar
+ 2
If I use 1900 it shows leap year, but that is not a leap year
12th Aug 2021, 7:15 AM
Thasneem Mohamed
Thasneem Mohamed - avatar
+ 2
Thasneem, Following code will help in solving the problem, year = int(input()) if (year % 400 == 0): print("Leap year") elif (year % 100 == 0): print("Not a leap year") elif (year % 4 == 0): print("Leap year") else: print("Not a leap year") DHANANJAY PATEL
12th Aug 2021, 7:17 AM
DHANANJAY PATEL
DHANANJAY PATEL - avatar
+ 2
Superb Dananjay patel bro
12th Aug 2021, 7:23 AM
Thasneem Mohamed
Thasneem Mohamed - avatar
+ 2
Thasneem Mohamed If you read problem statement properly and do step by step then you can solve easily by doing this: 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") else: print ("Not a leap year")
12th Aug 2021, 8:16 AM
A͢J
A͢J - avatar
+ 2
Thasneem Mohamed Here is more easy solution: if year % 4 == 0 and year % 100 == 0 and year % 400 == 0: print ("Leap year") elif year % 4 == 0 and year % 100 != 0: print ("Leap year") else: print ("Not a leap year")
12th Aug 2021, 10:11 AM
A͢J
A͢J - avatar
+ 2
I think if you follow the problem statement exactly as they mentioned, it might turn out something like this. if (year % 4 == 0) and ((year % 100 != 0) or (year % 400 == 0)): print("Leap year") else: print("Not a leap year")
13th Aug 2021, 4:11 AM
Greeshma Akash
+ 1
Hi again! I think you deleted your previous question related to this(leap year) topic. So, I'm sharing this with you to make it even smaller. The problem is that not all years that divided by 100 and 4 are leap years. https://code.sololearn.com/cKVMRHfemVW0/?ref=app
12th Aug 2021, 3:10 PM
Python Learner
Python Learner - avatar
+ 1
Ok guys problem solved 😄
13th Aug 2021, 5:10 PM
Thasneem Mohamed
Thasneem Mohamed - avatar
0
You haven't made any mistake, it's working perfectly👍🏻👍🏻
12th Aug 2021, 7:08 AM
Parth
Parth - avatar
0
Thasneem Mohamed ooh, write your code like what DHANANJAY PATEL says
12th Aug 2021, 7:20 AM
Parth
Parth - avatar
14th Aug 2021, 5:02 AM
Arbaz Shaikh
Arbaz Shaikh - avatar