Project 4: Average Scores

  < Previous  Next >

Assignment id: project4
Required Files: project4.py, rubric4.txt

Due Date

See the calendar for due date.

Objectives:

Description:

Write a python script (with comments) that commutes the average score for an unknown number of students in a file. Specifically your script should:

Examples

For example, the following are examples of correct execution (with the text in bold being the input from the user):
Input file
project4-inputA.txt:
Output to the screen: Output file
"averages.csv"
Mary
76
89
82
100
Joey
91
81
83
95
Sally
92
93
90
97
Please enter the scores filename: project4-inputA.txt
You entered project4-inputA.txt
Opened scores file project4-inputA.txt
Mary scores: 76.0 89.0 82.0 100.0 average: 86.75
Joey scores: 91.0 81.0 83.0 95.0 average: 87.5
Sally scores: 92.0 93.0 90.0 97.0 average: 93.0
# Student name, grade average
Mary,86.75
Joey,87.5
Sally,93.0

Input file
project4-inputB.txt:
Output to the screen: Output file
"averages.csv"
Mary
76
89
82
100
Joey
91
81
83
95
Sally
92
93
90
97
Billy
86
88
91
67
Emma
98
79
95
89
Noah
85
92
96
90
Please enter the scores filename: project4-inputB.txt
You entered project4-inputB.txt
Opened scores file project4-inputB.txt
Mary scores: 76.0 89.0 82.0 100.0 average: 86.75
Joey scores: 91.0 81.0 83.0 95.0 average: 87.5
Sally scores: 92.0 93.0 90.0 97.0 average: 93.0
Billy scores: 86.0 88.0 91.0 67.0 average: 83.0
Emma scores: 98.0 79.0 95.0 89.0 average: 90.25
Noah scores: 85.0 92.0 96.0 90.0 average: 90.75
# Student name, grade average
Mary,86.75
Joey,87.5
Sally,93.0
Billy,83.0
Emma,90.25
Noah,90.75

Input file
fileDoesNotExist.txt:
Output to the screen: Output file
"averages.csv"
n/a
Please enter the scores filename: fileDoesNotExist.txt
You entered fileDoesNotExist.txt
Could not open scores file, [Errno 2] No such file or directory: 'fileDoesNotExist.txt'
n/a

Submission

Submit your python script and rubric using the handin program. For handin, for this lab, type the following in a terminal window exactly as it appears:
handin  project4  project4.py  rubric4.txt
To verify your submission, type the following in a terminal window:
handin  project4

Rubric:

Points       Item
----------   --------------------------------------------------------------
_____ / 18   Meaniful comments
_____ / 20   Opens files correctly (and handles IO exceptions)
_____ / 30   Processes the scores file correctly
_____ / 20   Writes to "averages.csv"
_____ / 10   Closes the files
_____ /  2   Completed rubric (estimates for each line including hours spent)

_____ /100   Total


_____  Approximate number of hours spent

Notes

  1. Before writing any code, design a flowchart of how your algorithm will work. Then, write the comments. Then, get just the prompt working. Verify that it works. Then, open the file. Then, verify that the file open correctly, Then, work on the next steps.
  2. Optionally, you can replace typing from the keyboard with the contents of a file. For example, try on ranger:
    python3 project4.py  <  /nfshome/hcarroll/public_html/1170/private/projects/project4-stdinA.txt
    If you want to match my output exactly, then run the following on ranger:
    python3  project4.py  <  /nfshome/hcarroll/public_html/1170/private/projects/project4-stdinA.txt  >  outputA.txt
    diff /nfshome/hcarroll/public_html/1170/private/projects/project4-answerKeyA.txt  outputA.txt
    If the two files match exactly (which is what you want) then there should be NO output from diff. If diff shows one or more differences, fix them and run it again. To get side-by-side output (with the answer key on the left and your output on the right), replace the last line with:
    diff  --side-by-side  /nfshome/hcarroll/public_html/1170/private/projects/project4-answerKeyA.txt  outputA.txt
    For details about interpreting the output of diff, see the Using diff section on the Misc. webpage.