Marks¶
A list of marks corresponding to an exam consists of sublists
of two elements: the student identifier (str) and their mark
(float). You may suppose that the list is not empty.
Save the following functions into the file marks.py:
Write the function
search_ident()that takes alistof marks and a student identifier (str), and returnsTrueif the given identifier belongs to the list andFalseotherwise. Examples:>>> l = [['44444444D',8.3],['11111111A',7.25],['88888888H',4.1],['22222222B',3.8]] >>> search_ident(l,'88888888H') True >>> search_ident(l,'33333333C') False >>> search_ident([],'11111111A') False
Note
More tests are provided in the file
test-marks-1.txt.Write the function
search_mark()that takes alistand a mark (float), and returnsTrueif there is at least one student having this mark andFalseotherwise. Examples:>>> l = [['44444444D',8.3],['11111111A',7.25],['88888888H',4.1],['22222222B',3.8]] >>> search_mark(l,7.25) True >>> search_mark(l,5.0) False >>> search_mark([],6.5) False
Note
More tests are provided in the file
test-marks-2.txt.Write the function
perc_passed()that takes alistof marks, and returns the percentage (float) of students who have passed the exam. Examples:>>> l = [['44444444D',8.3],['11111111A',7.25],['88888888H',4.1],['22222222B',3.8],['66666666F',5.3]] >>> round(perc_passed(l), 2) 60.0 >>> l = [['3A', 5]] >>> round(perc_passed(l), 2) 100.0 >>> l = [['1A', 2], ['2B', 1], ['3C', 4]] >>> round(perc_passed(l), 2) 0.0
Note
More tests are provided in the file
test-marks-3.txt.Write the function
best_worst_mark()that takes alistof marks, and returns the best mark (float) and the worst mark (float) in the list. Examples:>>> l = [['44444444D',8.3],['11111111A',7.25],['88888888H',4.1],['22222222B',3.8],['66666666F',5.3]] >>> m, p = best_worst_mark(l) >>> m 8.3 >>> p 3.8 >>> l = [['3A', 5]] >>> m, p = best_worst_mark(l) >>> m 5 >>> p 5
Note
More tests are provided in the file
test-marks-4.txt.Write the function
mark_distribution()that takes alistof marks, and returns anotherlistwith 11 items that represents the marks distribution between 0 and 10. The first item in the list will be the number of marks belonging to the interval [0, 1[; the second item will be the number of marks belonging to the interval [1, 2[; and so on. The last (11th) item will contain the number of marks equal to 10. Examples:>>> l = [['44444444D',8.3],['88888888H',4.1],['22222222B',4.8],['66666666F',5.3],['99999999J',10.0]] >>> dn = mark_distribution(l) >>> dn [0, 0, 0, 0, 2, 1, 0, 0, 1, 0, 1] >>> l = [['3A', 5]] >>> dn = mark_distribution(l) >>> dn [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0] >>> l = [['1A', 2], ['2B', 1], ['3C', 4]] >>> dn = mark_distribution(l) >>> dn [0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0]
Note
More tests are provided in the file
test-marks-5.txt.Write the function
best_students()that takes alistof marks, and returns anotherlistwith the identifiers (str) of those students whose mark is 10. This list must be sorted increasingly. Examples:>>> l = [['44444444D',8.3],['88888888H',10.0],['33333333C',10.0],['22222222B',4.8],['66666666F',5.3],['99999999J',10.0]] >>> ld = best_students(l) >>> ld ['33333333C', '88888888H', '99999999J'] >>> l = [['3A', 10]] >>> ld = best_students(l) >>> ld ['3A'] >>> l = [['3A', 5]] >>> ld = best_students(l) >>> ld []
Note
More tests are provided in the file
test-marks-6.txt.Write the function
sort_ident()that takes alistof marks, and returns alistwith the same items sorted by increasing identifiers. Examples:>>> l = [['44444444D',8.3],['88888888H',10.0],['33333333C',10.0],['22222222B',4.8],['66666666F',5.3],['99999999J',10.0]] >>> ld = sort_ident(l) >>> ld [['22222222B', 4.8], ['33333333C', 10.0], ['44444444D', 8.3], ['66666666F', 5.3], ['88888888H', 10.0], ['99999999J', 10.0]]
Note
More tests are provided in the file
test-marks-7.txt.Write the function
sort_marks()that takes alistof marks, and returns alistwith the same items sorted by increasing marks firstly and increasing identifiers secondly. Examples:>>> l = [['44444444D',8.3],['88888888H',10.0],['22222222B',4.8],['66666666F',5.3]] >>> sort_marks(l) [['22222222B', 4.8], ['66666666F', 5.3], ['44444444D', 8.3], ['88888888H', 10.0]]
Note
More tests are provided in the file
test-marks-8.txt.Write the function
average()that takes alistof marks, and returns the average mark (float). Examples:>>> l = [['44444444D',8.3],['88888888H',10.0],['22222222B',4.8],['66666666F',5.3]] >>> round(average(l), 2) 7.1
Note
More tests are provided in the file
test-marks-9.txt.
Solution
A solution of these functions is provided in the file marks.py.