Grade Computing

The context is the process of calculating the final grade of a student given his/her grades from 4 CATs and the FINAL exam. This information is received in a single text (str) with exactly 5 sentences, each ended by a '\n' character. The sentences are not necessarily ordered. Each sentence is a text with the following common features:

  • The grade value is always at the end of the sentence, always preceded by one space (' ') and inmediately followed by the end of line character '\n'.

  • The sentences with the cat’s grade always include the word CAT inmediately followed by the number. For instance, "My CAT4's grade it's ok: it's 5.0.\n".

  • The sentence with the final exam grade has no 'CAT' substring and has the value of the grade at the end as well.

We wish to get a text indicating the weigthed average grade corresponding to that student in a sentence like: 'Your weigthed average grade is 7.05.'

The weights for the various input grades is as follows:
  • The CAT’s grade is obtained by averaging the CATs grades with the following weights: CAT1 is 10% and the rest is 30%.

  • The final grade is obtained by the average of CAT grade and Final exam grade (both 50%).


You are required to deliver the following functions (they have the same grade weight) in the module grades_module (file grades_module.py):

Firstly, an auxiliar function specified as follows:

grd_xtr(s)

such that

given s, a str with a sentence with the grade from one exam as described above.

returns

  • an int with either the number of the CAT in the sentence (hence, 1,2,3 or 4) or 0 if it is the grade from the final exam.

  • a float with the grade

For example,


>>> s = "My CAT4's grade is 5.0"
>>> grd_xtr(s)
(4, 5.0)

>>> s = 'My CAT1 was not very good since my grade is 3.5'
>>> grd_xtr(s)
(1, 3.5)

Doctests are available in the grd_xtr.test file.


Secondly, the main function:

grd_clc(s)

such that

given s a str with the text with the five sentences about a student’s grades, as described above.

returns a str indicating the final grade of the student in the format described above. The grade must be rounded to 2 decimals.

For instance,


>>> s = "My CAT4's grade it ok: it is 5.0\n"
>>> s += "My CAT1 was not very good since my grade is 3.5\n" 
>>> s += "Then in CAT2 is 5.0\n"
>>> s += "For CAT3 the grade I've got is 7.5\n"
>>> s += "And finally I'm very happy of my grade in the final exam: it is 8.5\n"
>>> grd_clc(s)
'Your weigthed average grade is 7.05.'

Warning

This function must be implemented by calling the previous function.

Doctests are available in the grd_clc.test file.