Advertisement
Fhernd

ValidMonth.py

Jan 25th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. import string
  2. # -----------
  3. # User Instructions
  4. #
  5. # Modify the valid_month() function to verify
  6. # whether the data a user enters is a valid
  7. # month. If the passed in parameter 'month'
  8. # is not a valid month, return None.
  9. # If 'month' is a valid month, then return
  10. # the name of the month with the first letter
  11. # capitalized.
  12. #
  13.  
  14. months = ['January',
  15.           'February',
  16.           'March',
  17.           'April',
  18.           'May',
  19.           'June',
  20.           'July',
  21.           'August',
  22.           'September',
  23.           'October',
  24.           'November',
  25.           'December']
  26.          
  27. def valid_month(month):
  28.     month = month.lower()
  29.     month = string.capwords(month)
  30.    
  31.     if month in months:
  32.         return month
  33.     else:
  34.         return None
  35.  
  36. # valid_month("january") => "January"    
  37. # valid_month("January") => "January"
  38. # valid_month("foo") => None
  39. # valid_month("") => None
  40.  
  41. print valid_month("may")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement