Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use python. There are 2 input files included with these directions in the screenshots. The salesperson.txt file has salesperson's names and their sales of a

use python.

There are 2 input files included with these directions in the screenshots. The salesperson.txt file has salesperson's names and their sales of a widget for the last 8 months (Figure 1). The other file, average.txt, reports the average monthly sales for each month from the previous year (Figure 2). The two screenshots show how the files look in structure:

Figure 1

Figure 2

image text in transcribed

The salesperson.txt file will become a two-dimensional list within the program. The average.txt file will be a normal list within the program. For the output file you will need to set up columns.

The main function will set up empty lists and call the following four functions.

The first function is a value-returning function which opens the salesperson.txt file, reads this into a two-dimensional list, closes the file, and returns the list.

The second function is a value-returning function which opens the average.txt file, reads this into a list, closes the file, and returns the list.

The third function is a void function and writes headings to file.

The fourth function is a void function and writes data to file.

Note: There will be a fifth function, a value-returning function called from the fourth function, which decides the level of sales and returns the level.

The output file will appear like the screenshot image below:

Figure 3

image text in transcribed

Here are some hints on how the solution was created (there are many other ways to do this):

Declare and initialize your list variables in the main function.

In the first value-returning function (called from main) use a for-loop with a file object variable for the salesperson.txt file to read the file into a two-dimensional list. If you use the "Split" function from Chapter 8 you can create the two-dimensional list with this one for-loop.

In the second value-returning function (called from main) use another for-loop with a file object variable for the average.txt file to read the average monthly sales into a list (I stripped the newline from this when I appended the data to the list).

Do not forget to close each file in the functions for the two bullets above.

Test the program at this point and make sure both the lists look okay. You can use a print statement for testing, but remove it once the lists look okay. Your two lists should like Figures 4 and 5 below when printed. Figure 4 may look different depending on the screen size.

Figure 4

Figure 5

image text in transcribed

If you notice in Figure 4, it is a two-dimensional list. Each salesperson's record is within brackets and then all salespeople are within brackets. Figure 5 is a normal list.

Open the output file to write to it.

Next, in a void function (called from main), write your heading to file. Again, check your output file before continuing to make sure the headings look okay.

The last function (called from main) will complete most of the calculations. Declare and initialize any variables needed for this. You will use a nested loop, that is, an outer loop (this will loop based on each list within the salesperson 2-Dimensional list) with an inner loop that will loop based on the length of the answer list. There are many ways to go about this, which is why the directions are a bit vague on this. Some suggestions might be:

Take care of the name in the outer loop code, meaning you loop through the month sales in the inner loop and compare them to the average list (and keep track of how many are above average) and so the name is done prior to the inner loop.

In the outer loop, when working with the name, you will need to use some sort of code to switch the name from LastName, FirstName to FirstName LastName (e.g., Smith, Mary --> Mary Smith).

Use a decision in the inner loop to see how many months are above the average for that salesperson.

Once out of the inner loop (but still in the outer loop) use number above average (from the bullet above) to get percentage above average.

Use the final value-returning function at this point to obtain the sales level, as follows:

If their sales percentage is 59.99% or lower they are at Level ONE

If their sales percentage ranges from 60.00-74.99% they are at Level TWO

If their sales percentage ranges from 75.00-89.99% they are at Level THREE

If their sales percentage ranges from 90.00 to 100% they are at Level FOUR

Still in the outer loop print this salesperson to file (based on Figure 3 above).

Reset the variable that holds the number of months above average for a salesperson to null value for the next salesperson.

Remember, when writing this program, it should be written so it can be used for other files, meaning files with more than 8 months. Thus, in the code never use a static number "8." Rather, use the length of the average list for calculations and output.

Do not forget to close the output file at the end of the main function.

When you code these programs make sure you use proper variable naming and add comments to the program. Refer to the directions for variable naming conventions in Comments should include:

A comment for the program

A section comment introducing each function

Line comments for non-obvious code (such as loops and decisions)

In the first two value-returning functions (reading both files into the lists), use exception handling in case the files are not available.

Figure 1 Figure 2 Figure 3 Figure 4 Figure 5 [67,,59,70,69,72,58,65,79]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions