Programming Project 2

Programming Projects are to be submitted to gradescope.

Due date: Sep 19, Thursday at 7pm

In this programming project you will implement a number of Python functions to validate or transform values conditionally. Make sure you follow the provided style guide (you will be graded on it!). You are allowed to use round(), str() and len(), but other than that you are not allowed to use any other built-in method or function from any Python library.

Also make sure you check the Academic Integrity and Common Gradescope Errors pages.

Name the program grades.py. Make sure that gradescope gives you the points for passing the test cases.

letter_grade()

This function determines a letter grade (“A”, “B”, and so on) based on a float argument representing a percentage grade.

It returns a letter grade based on the following rules:

-   Greater or equal to 90, return "A"
-   Greater or equal to 80, return "B"
-   Greater or equal to 70, return "C"
-   Greater or equal to 60, return "D"
-   Anything less, than 60 return "E" but greater or equal to 0
-   If argument is negative or greater than 100, return "X"

pass_or_fail

This function determines if a student passed or failed a class, based on their final letter grade. Letter grades equal to “A”, “B”, “C”, or “D” are passing grades ("Pass").

Calculate percentage – point_grade function

This function calculates a percentage grade based on a score and total_points. It calculates the percentage grade by dividing score by total_points, and multiplies result by 100. It returns the calculated percentage as a float rounded at two decimals

Calculate final grade – get_grade_results function

This function takes two score and total_points, and it calls the previous functions you’ve written – DO NOT recalculate percentage of grade, letter grade, etc. in this function. You are required to call the other functions. It returns a message similar to: Your grade is 92.34 (A - Pass) or Your grade is 35.78 (E - Fail)

Test Cases

def main():
  # test letter_grade function
  assert letter_grade(90) == "A"
  assert letter_grade(80) == "B"
  assert letter_grade(70) == "C"
  assert letter_grade(60) == "D"
  assert letter_grade(59) == "E"
  assert letter_grade(-59) == "X"
  assert letter_grade(110) == "X"
  
  # test pass_or_fail function
  assert pass_or_fail("B") == "Pass"
  assert pass_or_fail("E") == "Fail"
  assert pass_or_fail("ABCD") == "Error"
  
  # test point_grade function
  assert point_grade(0, 100) == 0.0
  assert point_grade(100, 100) == 100.0
  assert point_grade(45, 80) == 56.25
  assert point_grade(37, 40) == 92.5
  
  # test get_grade_results function
  assert get_grade_results(0, 100) == "Your grade is 0.0 (E - Fail)"
  assert get_grade_results(45, 80) == "Your grade is 56.25 (E - Fail)"
  assert get_grade_results(37, 40) == "Your grade is 92.5 (A - Pass)"
  
main()