How to Calculate Weighscore in Python

There are a few ways to calculate student scores in order to get an average. One way to do so is to give each score a "weight," or higher value, than other scores. This can reflect the importance of one score, say a test, against another score. Using Python and its built-in mathematical capabilities, you can create a Python program that determines average scores in a weighted grading system.

Things You'll Need

  • Python interpreter
Show More

Instructions

    • 1

      Create a score list in the Python interpreter, complete with sample scores:

      >>>scores = [98.0, 78.5, 87.0, 85.4, 66.3]

    • 2

      Create another list containing the weights of each score. Each weight will correspond to the grade in the same index of the scores list. The weights must add up to 100 percent:

      >>>weights = [10.0, 10.0, 20.0, 30.0, 30.0]

    • 3

      Loop through each grade, multiply the decimal representation of the grade against the decimal representation of the weight, or each number divided by 100:

      >>>counter = 0
      >>>for x in scores:
      . . . scores[counter] = (x/100) * (weights[counter] / 100)
      . . . count += 1

    • 4

      Add all the new weighted scores together into a single "total" variable:

      >>>total = 0
      >>>for score in scores:
      . . . total += score

    • 5

      Multiply the total by 100. This is the weighted average:

      >>>average = total * 100
      >>>average
      80.56

Related Searches:

References

Comments

Related Ads

Featured