**New course!**Every coder should learn

**Generative AI!**

+ 5

# What is the answer for the “Leap Year” question

The question asks to print out “not a leap year” or “leap year” for any input of the year. I solved the question by several ways, yet the answers always went wrong. Can somebody help me to debug my code? 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")

10 Answers

- 3

thanks David Ashton i forgot that 😂😀

+ 1

Hey Weitao Sun
Year is a leap year if it is divisible by 4 but not by 100, except that years divisible by 400 are leap years. Therefore your condition will be like this
if ((year % 4 == 0 and year % 100 != 0) or year % 400 == 0)

+ 1

n=int(input("enter year:"))
if((n%4==0 and n%400==0) or n%100!=0):
print(n,"is leap year")
else:
Print(n,"is not a leap year")
#pythoncode

0

Weitao Sun. Here is a simple solution
https://code.sololearn.com/cOgB9UfjI1vp

0

I guess this one is simple 😀
https://code.sololearn.com/cQk9jOd1OeU2/?ref=app

0

This one might not be the simplest solution, but it works as expected in all the test cases.
https://code.sololearn.com/cCSu3kJ6F0vV/?ref=app

0

a = int(input())
print("Yes"*(a%4<1 and a%100 or a%400<1) or "No")
# Hope this helps

0

The second else should print "Leap year"

- 2

in the second else statement you should write "leap year"