Processing a CSV download.
★★☆The results of three unit assessments for a course can be downloaded from an examining body website in CSV format. The data in grade book.txt is formatted as: forename, surname, unit 1 result, unit 2 result, unit 3 result. This program reads the data and outputs the results from a chosen unit.
Raghu,Aleksandra,78,63,0
Michelle,Chase,34,56,0
Max,Clayton,89,88,0
Selene,Dipti,79,82,0
Damon,Smith,56,63,0
Helen,Sorina,90,90,0
Briana,Takehiko,76,87,0
Write a program that asks the user which unit to output the results for. The program then outputs the name of each student and the result they achieved in that unit.
Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.
read_grade_book that:output_assignment that:grade_book is declared.read_grade_book is called.output_assignment is called.Which unit do you want to output the results for? :1
Raghu Aleksandra: 78
Michelle Chase: 34
Max Clayton: 89
Selene Dipti: 79
Damon Smith: 56
Helen Sorina: 90
Briana Takehiko: 76
Which unit do you want to output the results for? :2
Raghu Aleksandra: 63
Michelle Chase: 56
Max Clayton: 88
Selene Dipti: 82
Damon Smith: 63
Helen Sorina: 90
Briana Takehiko: 87
Which unit do you want to output the results for? :3
Raghu Aleksandra: 0
Michelle Chase: 0
Max Clayton: 0
Selene Dipti: 0
Damon Smith: 0
Helen Sorina: 0
Briana Takehiko: 0
Restricted automated feedback
Automated feedback for this assignment is still under construction. Submitted programs are checked for syntax errors and their source code is checked for potential errors, bugs, stylistic issues, and suspicious constructs. However, no checks are performed yet to see if the program correctly implements the behaviour specified in the assignment.
# Grade book program
# -------------------------
# Subprograms
# -------------------------
# Read the CSV data from the file
---
def read_grade_book(filename):
---
file = open(filename, "r")
---
# Read each line of data until end of file
for record in file:
---
record = record.strip()
---
fields = record.split(",")
---
grade_book.append(fields)
---
file.close()
---
# Output the results from a single field for each student
def output_assignment():
---
unit = int(input("Which unit do you want to output the results for? :"))
---
for student in grade_book:
---
output = student[0] + " " + student[1] + ": " + str(student[unit + 1])
---
print(output)
---
# -------------------------
# Main program
# -------------------------
grade_book = []
---
read_grade_book("grade book.txt")
output_assignment()