-2

This code is what I came up with so far in reading out mm/dd/yyyy as month dd, yyyy what do I need to do to get the translation aspect of the code working?

date = input('Please enter a date in mm/dd/yyyy format: ')
month_list = ['January', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'November', 'December']

if date[0] == 0:
      month_num = date[1]
      print(month_list[month_num])
else:
      month_num = (date[0] *10) + date[2]
      print(month_list[month_num])

1 Answers1

0

You are on the right track. One of your problems is you are taking the wrong index position, since index starts at 0. You were also mising February and October from your list. This should work:

date = input('Please enter a date in mm/dd/yyyy format: ')
month_list = ['January', "February",'March', 'April', 'May', 'June', 'July', 'August', 'September', "October", 'November', 'December']

if date[0] == '0':
    month_num = int(date[1])
    print(month_list[month_num - 1])
else:
    month_num = (int(date[0]) *10) + int(date[1])
    print(month_list[month_num - 1])

WangGang
  • 533
  • 3
  • 15