i have enter dates in (mm/dd/yyyy) form. so, have 05/13/1999 when reporting date how remove 0 month. want still able read double digit months 11/12/1999
from functionax import disp_bday name = raw_input("enter name: ") s = date = raw_input("enter dob (mm/dd/yyyy): ") x = month = int((s[0:1]) year = s[6:10] print disp_bday(name, month, year)
functionax below
from datetime import date def display_birthday_wishes(name, month, year): p = current_year = date.today().year current_age = (int(p)-int(year)) if month == 1: month = 'carnations' elif month == 2: month = 'primroses' elif month == 3: month = 'daffodils' elif month == 4: month = 'sweet peas' elif month == 5: month = 'hawthorn flowers' elif month == 6: month = 'roses' elif month == 7: month = 'water lilies' elif month == 8: month = 'poppies' elif month == 9: month = 'asters' elif month == 10: month = 'calendulas' elif month == 11: month = 'chrysanthemums' elif month == 12: month = 'holly flowers' return "hi, " + name + ". " + str(current_age) +\ " years old year! here's bouquet of "+month+" you!"
this sounds want use regular expression this:
import re m = re.match(r'(\d{1,2})/(\d{1,2})/(\d{4})', date) if m: print disp_bday(m.groups()) else: print "invalid input"
take here more information on used expression