157k views
0 votes
Write a program that reads a string from the user containing a date in the form mm/dd/ yyyy. It should print the date in the form April 12, 2017. Hint: Get the "mm" from the user entered date "mm/dd/yyyy", then convert the "mm" into a month number. You may use an list month_list

1 Answer

2 votes

Answer:

months_info = ['January', 'February','March','April', 'May','June', 'July','August', 'September', 'October', 'November', 'December']

date = input('Enter a date using the mm/dd/yyyy format ')

m, d, y = date.split('/')

m = int(m) - 1

name_of_month = months_info[m]

print('{} {}, {}'.format(name_of_month, d, y))

Step-by-step explanation:

  • Create a list of all months and store them in the months_info variable.
  • Get the date as an input from user and then split the date.
  • Finally display the date by following the specific layout using the built-in format method.
User Knu
by
4.1k points