Instructions

  • The source code you submit must be entirely your work and must be written entirely during the class period. The use of any pre-existing code (other than that provided as part of the exam) is prohibited.

  • You must login using the username student (which does not have a password), not using your eid.

  • You may only use a terminal/shell window, Thonny and a web browser. The only page you may load in the WWW browser is the course submission site.

  • Your code need not comply with the course style guidelines and need not include comments.

  • You must submit your code using Gradescope.

  • Your last submission is the one that will be graded. No limit will be placed on the number of submissions but, obviously, you must complete the exam during the class period and submissions take time.

Grade Calculator

When calculating grades, teachers often want to know what the class average is and may want to separate scores into different grading categories. You will be performing both of those functions in your code today.

For the purpose of the exam, you must write one program grade_calculator.py. This program will implement two functions:

  • average - This function will take a single list of floats. It will return a float value that is the average of all valid entries in the provided list. Some entries in the list may be equal to -1.0, representing students who have dropped the course. You may assume that the list will contain at least one valid entry. For example:

    print(average([-1.0, 100.0, 90.0])) # Prints 95.0
    print(average([50.0, 90.0]))        # Prints 70.0
    print(average([-1.0, 100.0, -1.0])) # Prints 100.0
  • grade_totals - This function will take a list of tuples where each tuple represents the score for a single assignment. The first entry in each tuple represents the category associated with the assignment, for example: “Lab” or “HW”. The second entry will be a float representing the numeric score. The function must return a dictionary mapping from each category to the total score in that category. For example:

    scores = [("Lab", 100.0), 
              ("HW", 80),
              ("Lab", 90)]
    totals = grade_totals(scores)
    
    print(totals)      # Prints {"Lab": 190.0, "HW": 80.0}

    Note that "HW" and "Lab" are only examples. Any valid string may be used as a category title.

Back to Top