You are required to work on this lab in teams of two. You must complete this lab with your teammate only, although you may discuss lab concepts with other students. Please keep the Academic Integrity Policy in mind---do not show your code to anyone outside of the professors and tutors, and do not look at anyone else's code for this lab. If you need help, please post a question on Piazza, or contact the professor.
In this project, you will practice computing with strings and using functions. I kept it relatively short, so you will have enough time to complete it before the exam and get some practice. Save your code in a file whose name consists of the first letter of your first name followed by your last name and Prg2. For example, if I submitted an assignment, I would name the file mgagnePrg2.py.
In the U.S., dates are typically written in the format MM-DD-YYYY, but that format is not used in much of the rest of the world. In this assignment, you will write a program that takes a date in this format and transform it into others.
Your program should ask the user to enter a date in the format MM-DD-YYYY (e.g. 02-18-2020). Your program does not need to check that a date with the proper format was entered, you can assume that the user entered the date properly.
The program should print three things:
Your program is required to contain the following functions:
getDay
that takes one input parameter, a string containing a date in the format MM-DD-YYYY, and outputs a string containing the day substring of the dategetMonth
that takes one input parameter, a string containing a date in the format MM-DD-YYYY, and outputs a string containing the month substring of the dategetYear
that takes one input parameter, a string containing a date in the format MM-DD-YYYY, and outputs a string containing the year substring of the dateformat1
that takes three input parameters, a string containing the day (DD), a string containing the month (MM) and a string containing the year(YYYY), and outputs a string containing a date in the format YYYY-MM-DD.format2
that takes three input parameters, a string containing the day (DD), a string containing the month (MM) and a string containing the year(YYYY), and outputs a string containing a date in the format DD-MM-YY.format3
that takes three input parameters, a string containing the day (DD), a string containing the month (MM) and a string containing the year(YYYY), and outputs a string containing a date in the format "month-day-year".Your program should also contain a function main
that acts as the user interface, asks the user to enter a date in the format MM-DD-YYYY, transforms it into the various other formats and displays the result on screen.
To complete all the functions except for format3
, you should only need slices and operators on strings. To complete format3
, you should not use any conditional statements, you should only use slices, operators and the string method replace
. Doing this will require a little bit of unconventional thinking, feel free to come to me or the tutors for help if you are having trouble with this.
Like the previous assignment, your submitted assignment should start with a header containing the name of the author(s), filename, description of the program, input and output.
Make sure you test your program with a variety of possibilities for date, but you only need to test it on valid inputs, your program is allowed to behave arbitrarily on invalid dates.