COSC 1306 Spring 2021 Assignment 9: Strings, Functions, and Exception Handling [1] Objectives: This assignment’s primary purpose is to practice processing strings, handling exceptions, and to divide...

1 answer below »
This is my professor's instructions I do not know how to go about it to get the output


COSC 1306 Spring 2021 Assignment 9: Strings, Functions, and Exception Handling [1] Objectives: This assignment’s primary purpose is to practice processing strings, handling exceptions, and to divide tasks into functions. There is the primary data structure you have to pass around the functions to get the tasks done. Unfortunately, we have not discussed the use of files yet. So you will have to enter the data manually. You will decide the parameters and local variables to use. Do not use global variables. [2] Description: Now that many Americans have received COVID-19 shots, it is time to build a system to track the vaccination date. Suppose the vaccination data comes in in a $-Separated Values, similar to the more popular Comma-Separated Values (CSV). Here is a sample: Doe$Jane$12/02/00$Moderna$03/11/21$04/13/21 Five dollar signs separate six values. The six values represent last name, first name, DoB, Vaccination product, first V-date, and second V-date. We avoid using CSV because a comma may be used in the product’s name, such as “Pfizer, Inc,” making CSV fail. Data structure. The primary data structure you will use is a table (a list of tuples) with some experience before. Similar to the last assignment, there is a minor conversion issue. Typically, we use date in the form of MM-DD-YY, but that is not an international standard, and it makes sorting difficult. You may have noticed that I prefer the YYYY-MM-DD format, such as 2021-04-12 (with or without ‘-‘). You will have to do the conversion. For years (YY) between 00 and 21, treat them as 20YY; otherwise, make it 19YY. That is the best we can do. You can get the program to work first and then come back to add this conversion. I suggest that you do the conversion early in the code. Keep in mind that tuples are immutable, so better make the change before you put everything into a tuple. Here is what you need to do.  Build the table by getting the data in DSV format, check for error  Print the table  Sort the table based on the date of the second shot.  Print the sorted table. table = build_table() print_table(table) table.sort(key=lambda x:x[5]) print_table(table) The program is relatively short. One can do a lot by calling library functions to do the work in Python. The code that I tested is less than 35 lines. [3] Requirements: I am giving you the main program. One reason is to force you to keep the main program simple (mainly calling some functions) and organized. A second reason is to give you the lambda function for the sorting. The third reason is to force you to use sort() instead of sorted().  Use the main program as is. Do not modify it. You should write the functions to make it work.  You will need to write other functions, not just the ones mentioned in the main program.  You will have to check for errors or exceptions (try-except) when getting the input. At the minimum, handle the case when there are less than six values in the input. Keep asking the user to provide the data.  The input phase ends when the user enters an empty string. [4] Input and Output: See sample outputs below and the demo in class. To make it easier to test, I have prepared several strings here so you can copy and paste them into the IDE. These are just for testing the code. The TA may test it with other strings. Try copy 4 or 5 values and see if your exception handling works. Smith$John$02/28/95$Pfizer$01/25/21$02/23/21 Doe$Jane$12/02/00$Moderna$03/11/21$04/13/21 Carter$James$09/01/55$Johnson and Johnson$02/01/21$03/02/21 [5] Deadline: Midnight, Monday, April 19, 2021. Please enter a record: Smith$John$02/28/95$Pfizer$01/25/21$02/23/21 Please enter a record: Doe$Jane$12/02/00$Moderna$03/11/21$04/13/21 Please enter a record: Carter$James$09/01/55$Johnson and Johnson$02/01/21$03/02/21 Please enter a record: Last Name First Name DoB Vaccine Product 1st V-Date 2nd V-Date Smith John 1995-02-28 Pfizer 2021-01-25 2021-02-23 Doe Jane 2000-12-02 Moderna 2021-03-11 2021-04-13 Carter James 1955-09-01 Johnson and Johnson 2021-02-01 2021-03-02 Last Name First Name DoB Vaccine Product 1st V-Date 2nd V-Date Smith John 1995-02-28 Pfizer 2021-01-25 2021-02-23 Carter James 1955-09-01 Johnson and Johnson 2021-02-01 2021-03-02 Doe Jane 2000-12-02 Moderna 2021-03-11 2021-04-13
Answered 1 days AfterApr 16, 2021

Answer To: COSC 1306 Spring 2021 Assignment 9: Strings, Functions, and Exception Handling [1] Objectives: This...

Pratap answered on Apr 18 2021
142 Votes
"""
DSV(Dollar Separated Values) Processor Program
program will get dsv input by user
processes i
t and display in normal and sorted tables
"""
def user_input():
"""
Function to get dsv string input by the user
:return: list of processed data
"""
content = []
while True:
try:
user = input("Please enter a record: ")
if user:
data = user.split("$")
if len(data) == 6:
for i in data:
if len(i) == 0:
print("Empty value found. Try again!")
raise ValueError
else:
content.append(data)
continue
else:
print("Provided record is invalid")
continue
else:
return content
except:
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here