# File: datecvt.py # Program to convert dates from European to US format and a short and long format # # Matt Bishop, MHI 289I, Fall 2020 # # read the date # eurdate = 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 # datelist = eurdate.split('/') day = int(datelist[0]) month = int(datelist[1]) year = int(datelist[2]) 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 ))