Python Lists, Tuples and Functions Tasks to do: (a) Write a function with the name get_grade that
Question:
Python Lists, Tuples and Functions
Tasks to do:
(a) Write a function with the name get_grade that takes in thetotal marks as input and calculates the grade according to thefollowing table:
Note that according to the rules, the total points scored by thestudent are rounded to the nearest integer before assigning them agrade.
(b) The second function you need to write is calculate_sgpa.This function takes in three inputs – each input representing agrade received in a subject – and calculate the Semester GPA (SGPA)based on the point equivalent of the grades. For instance, if thefunction is called with the grades ’A’, ’A’ and ’D’, it will returnSGPA of 3.0 since (4+4+1)/3 = 3.0.
However, this function also allows the caller to calculate SGPAof less than three subjects. The way to do this is to send thevalue ’nothing’ as one or two of the arguments. For example, if thefunction is called with the values ’A’, ’B’, ’nothing’, it shouldreturn 3.5.
The exact method for calculation of SGPA is given in theAlgorithm 1. In this algorithm, the symbol ? isthe assignment operator and ‘increment’ means to increase thevalue of a variable by one.
(c)
Write third function with the name find_cumulative_marks. Thisfunction will be given a list of tuples. For example:
results = [
(’2200001234’, ’Abdullah AlGhamdi’, 64, 78.5, 89, 25, 99), (’2200001235’, ’Hassan AlOtaibi’, 14, 28.5, 83, 76),
(’ 2200001236’, ’Khalid AlShahrani’, 87, None, 1.6)
]
Each tuple represents the scores of a student. The first elementis the university ID of the student and the second is the fullname. The rest of the elements are the student’s score inassignments.
Some students may have submitted more assignments than theothers. For instance, in the example above, the first student hassubmitted 5 assignments while the third has submitted only 3 (ofwhich, the second got a None – meaning it was invalidated). A Nonein the score is the same as a 0.
Your mission, should you choose to accept it, is to writefind_cumulative_marks in a way that it returns the cumulative marksof each student. So, for the case above, it should return a list oftuples as follows:
[
(’2200001234’, ’kristen mark’, 355.5), (’2200001235’, ’Davidsmith’, 201.5), (’2200001236’, ’maria Olsen’, 88.6)
]
Your function should be able to handle any number of tuplesi.e., student records passed to it. If a None is passed to thefunction, it should return a None back. If an empty list is passed,it should, obviously return an empty list back. Make sure youpreserve the order of the tuples within the outer list.