Question
Practice the following in Python: File operations: read and write Various data structures: list, dictionary, and/or tuples Background: have a student file; Each line is
File operations: read and write
Various data structures: list, dictionary, and/or tuples
Background: have a student file; Each line is a record of one student. Information includes student names, assignment points, egzam points, and project points. Examples are shown below. . separates the data elements. The data file is shown below.
Karen, 134, 100, 40
Juni, 190, 190, 96
Sani, 180, 160, 80
Lila, 170,170, 70
Program: Please rewrite the Python program with different data structures. You can use list, dictionary, and/or tuples, at least two of them in combination. For example, a list of students. Each student is a dictionary. Or each student is a tuple. And so on. It is up to you. Your program reads through the file and processes each record/line. At the end, you would like to print out:
how many students in the file?
Average student scores in terms of percentage
which student (show student name) has the highest score?
how many A students?
Enhance your program by allowing users to enter the data filename. If the filename does not exist, please say so and end your program gracefully.
*please sort the list of students by percentagedescendingand write the sorted list to a file.*
The sorted student information should be written into an output file named sorted.txt. For each student, please include student name, then percentage, and letter grade at the end, with a tab in between. It is up to you whether to include points for assignments, egzams, and projects as part of the student record. The last line of the file should contain your name.
Example:
the data file name>students.txt
Number of students: 4
===Summary===
Juni has the highest percentage 95.20%
Number of A students is 1
Class average is 79.0
finished writing.
With the wrong file name:
the data file name > student.txt
No such file.
sorted.txtshould look like
Karen 134.0 100.0 40.0 54.80% E
Juni 170.0 170.0 70.0 82.00% B
Sani 180.0 160.0 80.0 84.00% B
Lila 190.0 190.0 96.0 95.20% A
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started