# Program to convert dates from European to US format and a short and long format # Matt Bishop, Apr. 17, 2009 # for ECS 10 Spring 2009 # import string; # # read the date # eurdate = raw_input("Enter a date (dd/mm/yyyy):"); # # method 1: using ranges # day = int(eurdate[0:2]); month = int(eurdate[3:5]); year = int(eurdate[6:]); print "U.S. form done with ranges: %02d/%02d/%04d" % ( month, day, year ); # # method 2: using split # daystr, monthstr, yearstr = string.split(eurdate, '/'); month = int(monthstr); day = int(daystr); year = int(yearstr); print "U.S. form done with split: %02d/%02d/%04d" % ( month, day, year ); # # method 3. long form, done with list lookup # namesmonth = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; print "%s %d, %d" % ( namesmonth[month-1], day, year ); # # method 4. short form, done with range selection # abbrevmonth = "JanFebMarAprMayJunJulAugSepOctNovDec"; print "%s %d, %d" % ( abbrevmonth[3*(month-1):3*(month-1)+3], day, year );