Computer Science
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
Python
Python Funda
42 Likes
Answer
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)
Output
Enter date in MMDDYYYY format: 12252019
December 25, 2019
Answered By
19 Likes
Related Questions
One foot equals 12 inches. Write a function that accepts a length written in feet as an argument and returns this length written in inches. Write a second function that asks the user for a number of feet and returns this value. Write a third function that accepts a number of inches and displays this to the screen. Use these three functions to write a program that asks the user for a number of feet and tells them the corresponding number of inches.
Write a program that reads an integer N from the keyboard computes and displays the sum of the numbers from N to (2 * N) if N is nonnegative. If N is a negative number, then it's the sum of the numbers from (2 * N) to N. The starting and ending points are included in the sum.
Write a program that prints a table on two columns — table that helps converting miles into kilometres.
Write another program printing a table with two columns that helps convert pounds in kilograms.