Regarding the program like this, the else seems to be strange.When I try to run it in the terminal, it says SyntaxError: invalid syntax.Please let me know the solution.
a=input("Enter a number.a = "
a = int(a)
if a%4 == 0 and a%100! = 0:
print("This is a leap year.")
if a %400 == 0:
print("Leap year".Congratulations.")
else:
print("Not leap year")
if-else
indentation is not aligned.
modified:
if a %400 == 0:
print("Leap year".Congratulations.")
else:
print("Not leap year")
Cubick's answer is correct as a solution to the error being questioned.However, I guess that the logic that you want to code is to determine leap year.In that case, even if there are no errors in the syntax of the indentation, it is correct.If it's a question, it's an answer, but here are some examples of the correct logic and syntax.
if a%400==0 or (a%4==0 and a%100!=0):
print("Leap year".")
else:
print("Not leap year")
© 2025 OneMinuteCode. All rights reserved.