Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function reformat-date that takes a string argument containing a date in

ID: 3802453 • Letter: W

Question

Write a function reformat-date that takes a string argument containing a date in one format it and returns the date in another format. Specifically, it converts an argument like 10/31 2017' (MM/DD/YYYY) to 31-OCT-17' (DD-MMM-YY). The three-letter abbreviations in the return value must be given in all capital letters: JAN, FEB, MAR, APR, MAY, JUN, Nov, DEC. (Hint: don't need if statements to map month numbers to these strings. Try to think of another way. The returned day and year must be given as two-digit values, even if the first digit is a 0. The argument will not include leading zeroes. You may assume that the year is in the range 2000-2999, inclusive. Examples: Function Call Return Value reformat date 5/17/2021') 17-MAY-21' reformat date 12/31/2000') 31-DEC-00 reformat date 9/8/2017') 08-SEP-17' reformat date 8/5/2003') 05-AUG-03' Note that the quotation marks displayed in the examples are there to emphasize that the argument and return value are strings. You should not add quotation marks to your return values.

Explanation / Answer

def reformat_date(date):
group = date.split("/")
day = int(group[1])
year = group[2]

month_des = ["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"]
month = month_des[int(group[0]) - 1]

return "{:02}".format(day) +"-" + month + "-" + year[2:]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote