✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
INPUT FILE: marks.txt
Write a program processmarks.py that reads student records from a file. The name of the file is given as a command-line parameter. The file consists of multiple records, with one student record per line in the following format: / Skryf 'n program processmarks.py wat studenterekords uit 'n lêer lees. Die naam van die lêer word gegee as 'n opdragreëlparameter. Die lêer bestaan uit veelvuldige rekords, met een studenterekord per reël in die volgende formaat:
12345678 Surname FirstName T1 T2 P
The line consists of six fields, all separated with a space: the student number, the student's surname, the student's first name, two test marks, and a project mark. The marks are all either integers in the range 0 to 100, or a single "-" to indicate that no mark was awarded. / Die reël bestaan uit ses velde, elkeen geskei met 'n spasie: die studentenommer, die student se van, die student se voornaam, twee toetspunte en 'n projekpunt. Die punte is almal óf heelgetalle in die reeks 0 tot 100, óf 'n enkele "-" om aan te dui dat geen punt toegeken is nie.
The program must read all and display all of the marks neatly and, for each line, add the student's final mark. The final mark is calculated as F=0.25(T1+T2)+0.50P. At the end of the list of students, the program must display three extra lines with the minima, maxima, and averages of T1, T2, P, and the final marks. / Die program moet alles lees en al die punte netjies vertoon en vir elke reël die student se finale punt byvoeg. Die finale punt word bereken as F=0.25(T1+T2)+0.50P. Aan die einde van die lys studente moet die program drie ekstra reëls vertoon met die minimum, maksimum en gemiddeldes van T1, T2, P en die finale punte.
Then, use stdstats to display a histogram (bar graph) of the student marks sorted into ten bins: 0 .. 9.9, 10 .. 19.9, 20 .. 29.9, and so on. Hint: You will have to use stddraw.setCanvasSize() before and stddraw.show() after the call to display the bar graph. / Gebruik dan stdstats om 'n histogram (staafgrafiek) van die studentepunte te vertoon wat in tien bakke gesorteer is: 0 .. 9.9, 10 .. 19.9, 20 .. 29.9, ensovoorts. Wenk: Jy sal stddraw.setCanvasSize() voor en stddraw.show() na die oproep moet gebruik om die staafgrafiek te vertoon.
There are two important rules: / Daar is twee belangrike reëls:
If any mark field is "-", the corresponding mark is 0. / As enige merkveld "-" is, is die ooreenstemmende punt 0.
If any mark field contains an invalid value (less than 0 or more than 100), the entire line is ignored and *not* printed or used in the average calculation. / As enige merkveld 'n ongeldige waarde bevat (minder as 0 of meer as 100), word die hele reël geïgnoreer en *nie* gedruk of in die gemiddelde berekening gebruik nie.
For example, if marks.txt contains / Byvoorbeeld, as marks.txt bevat
34567890 Tyolo Thabo 78 - 8945678901 Lardo Luigi 101 62 5623456789 Brown Bobby 65 66 9312345678 Smith Sally - 84 71
the program must behave as follows: / die program moet soos volg optree:
$ python processmarks.py < marks.txt34567890 Thabo Tyolo 78 0 89 64.023456789 Bobby Brown 65 66 93 79.312345678 Sally Smith 0 84 71 56.5Min 0.0 0.0 71.0 56.5Max 78.0 84.0 93.0 79.3Average 47.7 50.0 84.3 66.6
Use the following statements to display the list: / Gebruik die volgende stellings om die lys te vertoon:
stdio.writef('%8s %-14s ', STUDENTNR, FIRSTNAME + ' ' + SURNAME)stdio.writef('%6d %6d %6d %6.1f\n', T1, T2, P, F)...stdio.writef('%-23s ', 'Average');stdio.writef('%6.1f %6.1f %6.1f %6.1f\n', AVERT1, AVERT2, AVERP, AVERF)
Download the following marks file: marks.txt and process it with your program. The last line should read / Laai die volgende puntelêer af: marks.txt en verwerk dit met jou program. Die laaste reël moet lees
Average 50.5 45.5 46.7 47.3and you should see this histogram: / en jy behoort hierdie histogram te sien: