Section 9.11 - ICS 104 Introduction to Programming Using Python and C Fall 24 zyBooks
Section 9.11 - ICS 104 Introduction to Programming Using Python and C Fall 24 zyBooks
Students:
Section 9.11 is a part of 1 assignment: Includes: zyLab
Lab12-Files-and-Exceptions
11/25/2024, 11:59 PM +03
Instructor note:
LAB
ACTIVITY 9.11.1: LAB: Course Grade 10 / 10
Write a program that reads the student information from a tab separated values (tsv) Ole. The program
then creates a text Ole that records the course grades of the students. Each row of the tsv Ole contains the
Last Name, First Name, Midterm1 score, Midterm2 score, and the Final score of a student. A sample of
the student information is provided in StudentInfo.tsv. Assume the number of students is at least 1 and at
most 20. Assume also the last names and Orst names do not contain whitespaces.
Read the Ole name of the tsv Ole from the user.
Open the tsv Ole and read the student information.
Compute the average exam score of each student.
Assign a letter grade to each student based on the average exam score in the following scale:
A: 90 =< x
B: 80 =< x < 90
C: 70 =< x < 80
D: 60 =< x < 70
F: x < 60
Compute the average of each exam.
Output the last names, Orst names, exam scores, and letter grades of the students into a text Ole
named report.txt. Output one student per row and separate the values with a tab character.
Output the average of each exam, with two digits after the decimal point, at the end of report.txt.
Hint: Use the format speciOcation to set the precision of the output.
StudentInfo.tsv
and the contents of StudentInfo.tsv are:
Barrett Edan 70 45 59
Bradshaw Reagan 96 97 88
Charlton Caius 73 94 80
Mayo Tyrese 88 61 36
Stern Brenda 90 86 45
the Ole report.txt should contain:
Barrett Edan 70 45 59 F
Bradshaw Reagan 96 97 88 A
Charlton Caius 73 94 80 B
Mayo Tyrese 88 61 36 D
Stern Brenda 90 86 45 C
main.py
20
21 file = open(fileName)
22 numoflines = file.readlines()
23 file.close()
24
25 report = open('report.txt', 'w')
26
27 for i in numoflines:
28 data = i.strip().split()
29
30 first= data[0]
31 last=data[1]
32 mid1=int(data[2])
33 mid2= int(data[3])
34 final=int(data[4])
35 mid1sum+= mid1
36 mid2sum +=mid2
37 finalsum += final
38 numofstudents +=1
39 grades= get_grade(mid1, mid2, final)
40 report.write(f'{first}\t{last}\t{mid1}\t{mid2}\t{final}\t{grades}\n')
DESKTOP CONSOLE
➜
Compare output
Input StudentInfo.tsv
2. Bradshaw Reagan 96 97 2. 88
Bradshaw
A Reagan 96 97 88
3. Charlton Caius 73 94 3. 80
Charlton
B Caius 73 94 80
6. 6.
7. Averages: midterm1 83.40, midterm2 76.60,
7. Averages:
final 61.60
midterm1 83.40, midterm2 76.60, fi
8. 8.
Compare output
Input StudentInfo1.tsv
3. Bradshaw Reagan 89 55 3. 38
Bradshaw
D Reagan 89 55 38
5. Charlton Caius 41 73 5. 75
Charlton
D Caius 41 73 75
Compare output
Input StudentInfo2.tsv
2. 2.
3. Averages: midterm1 80.00, midterm2 57.00,
3. Averages:
final 75.00
midterm1 80.00, midterm2 57.00, fi
4. 4.
Previous submissions
How was
this | Provide section feedback
section?
Completion details