Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CSCA20 - Lab 6

File Input/Output

Learning Objectives

We’re taking a break from learning about new features of python to focus on learning new ways of making our code interact with the world. In this lab, we can review a lot of what we’ve done already, but also put it to the test with much more data.

Prelab

Your prelab for this lab is your completed lab for lab 4.  So take some time to make sure you completed lab 4 as thoroughly as possible, and if you had trouble with lab4, this is a good opportunity to ask for help.

Demonstration & Evaluation

Successfully completing this lab will demonstrate competency in User Input/Output, Variables, Selection, Loops and File Input/Output. There will also be an opportunity to demonstrate mastery in user Input/Output, Variables, Loops.  You do not need to complete the mastery portion to demonstrate competency in the other areas.

The Scenario

The Union for Tracking Seaborn Contaminants (UTSC) was so pleased with the work you did for them in lab 4, they’ve asked you to improve the system. The program has grown, and now they have many rigs and much more data. So simply having users type everything in isn’t going to cut it anymore.

Menu

The same general menu should be presented as before, users should be able to add data, generate a report on totals, or generate a report on totals collected, or overload days

Adding Data

This time, instead of inputting data directly, the‘Add data’menu should ask the users to provide the name of a file (located in the same directory as the python file) containing the data to add to the system.

Input Files

The first line of the file consists of the number of rigs (ocean cleanup vessels) the project currently has.

The rest of the file consists of a line with the day number, followed by the amount of plastic collected by each rig on that day (one rig per line). The rig number will always be followed by a comma, and then the amount of plastic collected.

On some days, rigs are out of commission for repairs or testing. On those days, the rig’s total is replaced by the letters OOC.

A sample input file has been provided for you.

Calculating Totals

This should be the same menu options as in the previous version of the code (All dates or range of dates), but instead of just printing a single total kg to the screen. The code should prompt the user for the name of a file, and write the output to that file, with each line being the rig number, followed by a comma and then the total kg of plastic removed by that rig.

Calculating Overload Days

Once again, the menu options are the same as in previous version, but as with the totals, the output should be a file showing the number of overload days for each rig.

Mastery

To demonstrate mastery of user input/output in this lab, you must deal with invalid or improperly formatted user input in menu options or ranges.

You can also demonstrate mastery in variables and loops by only reading the file once.  For competency, you may get the user’s date range and/or threshold, then read the file and generate a list of totals/overload days. But for mastery, you’ll need to read the data once, when the user chooses to add the data, and then store it for use in multiple reports.  (As a hint, you’ll need a list of lists).

Hints

Here are a few hints that might help you with this assignment:

• Start by creating the code to read the file and get the various parts, just read, split, and then print out the data before you worry about calculating or storing anything

• speaking of split... the split function might be helpful here, check the python docs

• You can assume that the number of rigs provided at the start of the file is correct, that all rigs report every day (even if the report is OOC) and that they are always in exactly that order

• For competency, adding data can just store the file name, and then you can read the file once you have the date range/threshold values for any reports