CBSE Class 12 Computer Science
Question 102 of 105
Python Revision Tour — Question 8
Back to all questions 8
Question Write a program that reads a date as an integer in the format MMDDYYYY. The program will call a function that prints print out the date in the format <Month Name> <day>, <year>.
Sample run :
Enter date : 12252019
December 25, 2019
months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"]
dateStr = input("Enter date in MMDDYYYY format: ")
monthIndex = int(dateStr[:2]) - 1
month = months[monthIndex]
day = dateStr[2:4]
year = dateStr[4:]
newDateStr = month + ' ' + day + ', ' + year
print(newDateStr)Enter date in MMDDYYYY format: 12252019
December 25, 2019