-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIsleapBaby.py
47 lines (35 loc) · 1.64 KB
/
IsleapBaby.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# By Ashwath from forums
# A leap year baby is a baby born on Feb 29, which occurs only on a leap year.
# Define a procedure is_leap_baby that takes 3 inputs: day, month and year
# and returns True if the date is a leap day (Feb 29 in a valid leap year)
# and False otherwise.
# A year that is a multiple of 4 is a leap year unless the year is
# divisible by 100 but not a multiple of 400 (so, 1900 is not a leap
# year but 2000 and 2004 are).
def is_leap_baby(day,month,year):
# Write your code after this line.
if month!=2 or day!=29:
return False
elif year%4!=0:
return False
elif year%100 ==0 and year%400!=0:
return False
return True
# The function 'output' prints one of two statements based on whether
# the is_leap_baby function returned True or False.
def output(status,name):
if status:
print "%s is one of an extremely rare species. He is a leap year baby!" % name
else:
print "There's nothing special about %s's birthday. He is not a leap year baby!" % name
# Test Cases
output(is_leap_baby(29, 2, 1996), 'Calvin')
#>>>Calvin is one of an extremely rare species. He is a leap year baby!
output(is_leap_baby(19, 6, 1978), 'Garfield')
#>>>There's nothing special about Garfield's birthday. He is not a leap year baby!
output(is_leap_baby(29, 2, 2000), 'Hobbes')
#>>>Hobbes is one of an extremely rare species. He is a leap year baby!
output(is_leap_baby(29, 2, 1900), 'Charlie Brown')
#>>>There's nothing special about Charlie Brown's birthday. He is not a leap year baby!
output(is_leap_baby(28, 2, 1976), 'Odie')
#>>>There's nothing special about Odie's birthday. He is not a leap year baby!