-
Notifications
You must be signed in to change notification settings - Fork 0
/
Leap year py.txt
30 lines (21 loc) · 1.02 KB
/
Leap year py.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(1) If a year is evenly divisible by 4 means having no remainder
then go to next step. If it is not divisible by 4. It is not a
leap year. For example: 1997 is not a leap year.
(2)If a year is divisible by 4, but not by 100. For example: 2012,
it is a leap year. If a year is divisible by both 4 and 100, go to
next step.
(3)If a year is divisible by 100, but not by 400. For example: 1900,
then it is not a leap year. If a year is divisible by both, then it
is a leap year. So 2000 is a leap year.
# divided by 100 means century year (ending with 00)
# century year divided by 400 is leap year
if (year % 400 == 0) and (year % 100 == 0):
print("{0} is a leap year".format(year))
# not divided by 100 means not a century year
# year divided by 4 is a leap year
elif (year % 4 ==0) and (year % 100 != 0):
print("{0} is a leap year".format(year))
# if not divided by both 400 (century year) and 4 (not century year)
# year is not leap year
else:
print("{0} is not a leap year".format(year))