Westonci.ca is the Q&A platform that connects you with experts who provide accurate and detailed answers. Connect with a community of experts ready to help you find accurate solutions to your questions quickly and efficiently. Get precise and detailed answers to your questions from a knowledgeable community of experts on our Q&A platform.

Write a program that reads a string from the user containing a date in the form mm/dd/yyyy. If the user entered 12/10/2019, then it should print the date in the form December 10, 2019. solution in python.

Sagot :

Answer:

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

date = input("mm/dd/yyyy: ")

splitdate = date.split("/")

print(months[int(splitdate[0])-1]+" "+splitdate[1]+", "+splitdate[2]+".")

Explanation:

This line initializes a list of all 12 months

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

This prompts the user for date

date = input("mm/dd/yyyy: ")

This splits the date into three parts; mm with index 0, dd with index 1 and yy with index 2

splitdate = date.split("/")

The following prints the required output

print(months[int(splitdate[0])-1]+" "+splitdate[1]+", "+splitdate[2]+".")

Analyzing the print statment

splitdate[1] represents the day of the date

splitdate[2] represente the month of the date

However, in months[int(splitdate[0])-1]

First: splitdate[0] represents the month of the year as a string in numeric form e.g. "12", "01"

It is first converted to an integer as: int(splitdate[0])

Then the corresponding month is derived from the month list