Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import string
- # -----------
- # 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):
- month = month.lower()
- month = string.capwords(month)
- if month in months:
- return month
- else:
- return None
- # valid_month("january") => "January"
- # valid_month("January") => "January"
- # valid_month("foo") => None
- # valid_month("") => None
- print valid_month("may")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement