the question is a year is a leap if it is divisible by 4, unless it is a century year that is not devisible by 400. write a program that calculates whether a year is a leap or not

def main():
year = eval(input("Enter a year"))
if year/4 and year/400:

print("It is a leap year")
else:
print("Its not a leap year")

main()
this is wat i did. i dont understand why it only prints it is a leap year although i enter 1900 which is not devided by 400.......

Recommended Answers

All 4 Replies

1900/4 is not 0 and also 1900/400 is not 0, so the condition is fullfilled, you should use modulo (%).

i did

year = eval(input("Enter a year"))
if year<100 and year%4 ==0:

print("it is a leap year")

if year >100 and year%400==0:

print("it is a leap year")

else:
print("not a leap year")

it works for numbers bigger than 100 and for else: stateent but when i punch a number less than 100 like 8 it print it is a leap year and it is not a leap year i dont know why it prints 2 ?

8 is a leap year. 104 is also a leap year but your code will not catch it. In pseudocode:
1. Is the year evenly divisible by 4
2. Is the year evenly divisible by 100. If divisible by 4 and not by 100 it is not a new century and is a leap year.
3. If year is evenly divisible by 100 it is a new century. Centuries are only leap years if they are divisible by 400, so to be a leap century a year has to be evenly divisible by 4, 100, and 400. 2000 is a leap year; 1900, 1800, and 1700 are not leap years.

Please hit the [code] button for pasting code as indentation is significant.

year = eval(input("Enter a year"))
if year<100 and year%4 ==0:

print("it is a leap year")

if year >100 and year%400==0:

print("it is a leap year")

else:
print("not a leap year")

yea i did somethin like that but when i entr a number less than hundred and devisable by 4 it should say it is a leap year but instead it says it is a leap year and it is not a leap year so it executes else stateent too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.