-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalid_month.py
42 lines (34 loc) · 880 Bytes
/
valid_month.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
# -----------
# User Instructions
#
# Modify the valid_month() function to verify
# whether the data a user enters is a valid
# month. If the passed in parameter 'month'
# is not a valid month, return None.
# If 'month' is a valid month, then return
# the name of the month with the first letter
# capitalized.
#
months = ['January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December']
def valid_month(month):
if month in months:
return month
elif month.title() in months:
return month.title()
else:
return None
print valid_month("january") # => "January"
print valid_month("January") # => "January"
print valid_month("foo") # => None
print valid_month("") # => None