PLEASE USE PYTHON
Introduction
In this lab, you are writing a
function get_written_date(date_list) that takes as a
parameter a list of strings in
the [MM, DD, YYYY] format and returns the resulting date
(in the US format) as a string.
Note: we are using the US format for
strings: <MM>/<DD>/<YEAR>. For
example, 01/02/2022 can be represented as ['01',
'02', '2022'], which represents January 2nd, 2022.
Test Your Code
Instructions
Use the dictionary month_names that maps months to
their English names.
Note: the month key in the dictionary is stored
as an integer, however, in the input list it is
stored as a string in the MM format, e.g., "01".
Also, pay attention how the day is represented in the list and how
it is supposed to be output.
Troubleshooting
FINISH BELOW:
def get_written_date(date_list):
"""
The function ...
"""
month_names = {
1: "January",
2: "February",
3: "March",
4: "April",
5: "May",
6: "June",
7: "July",
8: "August",
9: "September",
10: "October",
11: "November",
12: "December",
}
# Finish the function
# Return the date string in written format
if __name__ == "__main__":
assert get_written_date(["01", "02", "2022"]) ==
'January 2, 2022'
assert get_written_date(["01", "12", "1970"]) ==
'January 12, 1970'
assert get_written_date(["04", "14", "2020"]) ==
'April 14, 2020'
assert get_written_date(["06", "19", "2000"]) ==
'June 19, 2000'
PLEASE USE PYTHON Introduction In this lab, you are writing a function get_written_date(date_list) that takes as a param
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am