Starting from:

$24.99

CS115 Lab 5- Tuples, Dictionaries, Lists Solution



[Q1A] Write a python program that will use a dictionary to store the sections of a course (keys) and for each section, a list of student id, grade pairs (tuple). You should define the following functions:

1. sectionAverages(): Takes a dictionary of sections(described above) as a parameter, and returns a list containing the average grades for each section in the dictionary.

2. changeSection() : Takes a dictionary, a student id, and a new section as parameters. The function should find the student with the given id in the dictionary, and if the current section is not the same as the section passed as a parameter, remove the student from the current section and add to the new section. If the id is not in the dictionary or the student is in the correct section already, return False, otherwise return True (student has been moved).

3. maxGrade(): Takes a dictionary as a parameter and returns a tuple containing the id and grade of the student with the maximum grade.

4. printDictionary(): takes a dictionary of sections as a parameter, and displays the dictionary as shown in the sample run.

[Q1B]
5. Write a python script that stores a dictionary containing sections of a course (keys) and a list of student id and grade tuples (values). Your program should do the following:
a. Read the file CS115.txt and store all student id/grades in the appropriate section list in the dictionary.
b. Displays the dictionary.
c. Finds and displays the average grade for all sections.
d. Changes student: 21641234 to section 2.
e. Changes student 22141734 to section 3.
f. Changes student 21112222 to section 3.
g. Display the updated dictionary.



Sample Run:
Section Data:
Section 1 :
('21641234', 78)
('22226549', 49)
('22054322', 100)
('21542417', 67)
('21313014', 59)
('22341546', 71) Section 2 :
('21341235', 68)
('22019415', 34)
('20981223', 71)
('25341234', 46) Section 3 :
('21451220', 82)
('21684592', 56)
('20059654', 95)
('21641264', 80)
('22141734', 92)
Section Averages: [70.66666666666667, 54.75, 81.0]
Section 1 :
('22226549', 49)
('22054322', 100)
('21542417', 67)
('21313014', 59)
('22341546', 71) Section 2 :
('21341235', 68)
('22019415', 34)
('20981223', 71)
('25341234', 46)
('21641234', 78) Section 3 :
('21451220', 82)
('21684592', 56)
('20059654', 95)
('21641264', 80)
('22141734', 92)
Student with highest score: 22054322 ( 100 )

More products