+ 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
13 Antworten
+ 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
+ 3
No bro my hidden case 1 and 7 shows it is wrong
+ 2
If I use 1900 it shows leap year, but that is not a leap year
+ 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
+ 2
Superb Dananjay patel bro
+ 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")
+ 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")
+ 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")
+ 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
+ 1
Ok guys problem solved 😄
0
You haven't made any mistake, it's working perfectly👍🏻👍🏻
0
Thasneem Mohamed ooh, write your code like what
DHANANJAY PATEL says