Scholarship Calculation

The university has decided a new scholarship policy for all 4-year long degrees. The terms of a scholarship for a given student depend on:

  • The year the student is coursing: int value.

  • The student’s average grade: a float value.

  • Whether the student is repeating or not: a bool value.

  • Whether the student’s situation is considered to require special support or not: a bool value.

The rules to calculate the scholarship amount are the following:

  • Any student can apply for a scholarship except those who are either repeating or did not pass (grade lower that 5.0).

  • Those who qualify will get a so-called fixed base amount (float) that might be incremented according to the following rules:
    • The base amount is incremented 25% for students in the 2nd, 3rd and 4th year.

    • To reward a good academic performance, an additional increment is applied depending on the student’s average grade according to the following terms:
      • Students in their 1st and 4th year who have got the maximum grade (10.0) will receive an additional 25% increment.

      • For students in their 2nd and 3rd year the criteria to be applied are the following:
        • If the grade is between 9.0 i 10.0 both included, they get a 20% increment.

        • If the grade is between 7.0 i 9.0 (7.0 included and 9.0 excluded) then the increment is a 10%.

        • No extra increment if the grade is lower than 7.0.

    • Besides that, any student that qualifies as special will get and additiontal 50% increment, independently of any previous increment.

The data provided to calculate the bill might contain errors. Hence, before calculating the amount, the data must be checked to determine whether is valid or not. If it is not then an error code (int) must be generated according to the following:

  • If the base amount is zero or negative then the hundreds digit in the error code must be 1.

  • If the year is not valid (it must be 1, 2, 3 or 4) then the tens digit must be 1.

  • If the grade is not valid (must be between 0.0 and 10.00 included) then the units digit must be 1.

For example, in case where the base amount is zero and the grade is 11.0 then the error code generated should be 101. If everything is correct then the error code should be 0. See more examples in the doctest of the first function below.

You are required to implement the following functions in the scholarship module (file scholarship.py):


The first funcion is:

scholarship_check(base, year, grade, rep, special)

such that

given base, year, grade, rep and special as specified above.

returns two values:

  • a bool which value is True if there is an error or False otherwise.

  • a int with the error code as described above (if the previous value is True), or 0 otherwise.

For example:


>>> scholarship_check (0.0, 4, 11.0, False, False)
(True, 101)

>>> scholarship_check (3000.0, 5, 6.0, False, True)
(True, 10)

>>> scholarship_check (3000.0, 5, 16.0, False, True)
(True, 11)

>>> scholarship_check (-3000.0, 5, 16.0, False, True)
(True, 111)

Additional doctests for validation are available in the scholarship_check-test.txt file.


The second funcion is:

scholarship_eval(base, year, grade, rep, special)

such that

given base, year, grade, rep and special as specified above and all being valid values,

returns a float with the amount of the scholarship given to that student according to the terms above.

For example:


>>> scholarship_eval (3000.0, 1, 8.5, False, False)
3000.0

>>> scholarship_eval (3000.0, 3, 10.0, False, False)
4500.0

>>> scholarship_eval (3000.0, 1, 4.5, False, True)
0.0

Additional doctests for validation are available in the scholarship_eval-test.txt file.


The third (and main) funcion is:

scholarship_calc(base, year, grade, rep, special)

such that

given base, year, grade, rep and special as specified above

returns two values:

  • a bool which value is True if there is an error and False otherwise.

  • either the error code (int) if an error has been found, or the amount of the scholarship given (float) calculated according to the terms above otherwise.

For example:


>>> scholarship_calc (3000.0, 1, 8.5, False, False)
(False, 3000.0)

>>> scholarship_calc (3000.0, 3, 10.0, False, False)
(False, 4500.0)

>>> scholarship_calc (3000.0, 1, 4.5, False, True)
(False, 0.0)

>>> scholarship_calc (0.0, 4, 11.0, False, False)
(True, 101)

>>> scholarship_calc (3000.0, 5, 6.0, False, True)
(True, 10)

>>> scholarship_calc (3000.0, 5, 16.0, False, True)
(True, 11)

Additional doctests for validation are available in the scholarship_calc-test.txt file.

Warning

The implementation of scholarship_calc function must call the two previous functions.