Here's the question:
Write a program that reads a string from the keyboard containing a date in the form mm/dd/yyyy and prints out the date in the form Month, Date, Year (See samples below). Your main function should handle all input from the user and printing. You should have another function, convertDate that takes the user input as an argument and returns the converted date string when called. Sample output below:
Please enter a date (format:mm/dd/yyyy):02/11/1995
Converted: February, 11, 1995.
I think i'm mostly done however what I don't get is how to take the user as an argument and return the converted date string when called.. as said in the question printing must all be done in the main function.
Here is my code:
Code:
def main():
date = raw_input("Please enter a date (format: mm/dd/yyyy): ")
datetest = date.split("/")
if datetest[0] == "01":
print "Converted: January,", datetest[1] + ",", datetest[2]
elif datetest[0] == "02":
print "Converted: February,", datetest[1] + ",", datetest[2]
elif datetest[0] == "03":
print "Converted: March,", datetest[1] + ",", datetest[2]
elif datetest[0] == "04":
print "Converted: April,", datetest[1] + ",", datetest[2]
elif datetest[0] == "05":
print "Converted: May,", datetest[1] + ",", datetest[2]
elif datetest[0] == "06":
print "Converted: June,", datetest[1] + ",", datetest[2]
elif datetest[0] == "07":
print "Converted: July,", datetest[1] + ",", datetest[2]
elif datetest[0] == "08":
print "Converted: August,", datetest[1] + ",", datetest[2]
elif datetest[0] == "09":
print "Converted: September,", datetest[1] + ",", datetest[2]
elif datetest[0] == "10":
print "Converted: October,", datetest[1] + ",", datetest[2]
elif datetest[0] == "11":
print "Converted: November,", datetest[1] + ",", datetest[2]
elif datetest[0] == "12":
print "Converted: December,", datetest[1] + ",", datetest[2]
else:
print "Invalid date entered."
def convertDate():
main()