Python - 24

Python - 24: Building a Score Tracker

Let's combine lists, loops, functions, and math to build a simple score tracker.

Your challenge: Find the total score, calculate the average, and create a function that returns the highest score.

✦ Python Editor
▶ Output

Add the scores

Start with total = 0, then loop through the list and add each score to the total.

Find the average

Divide the total by the number of scores: average = total / len(scores)

Find the highest score

A function can loop through the list and keep track of the largest value it has seen.

Start with the first score: highest = score_list[0]

Try it: Change the scores and add another value to the list.

Good Python habit: When finding the highest or lowest item in a list, start with an existing list value instead of guessing a starting number.

👀 Show Example Solution
scores = [100, 85, 92, 76, 95]

print("Player Scores:")

for score in scores:
    print(score)

total = 0

for score in scores:
    total = total + score

print("Total Score:")
print(total)

average = total / len(scores)

print("Average Score:")
print(average)

def highest_score(score_list):

    highest = score_list[0]

    for score in score_list:

        if score > highest:
            highest = score

    return highest

print("Highest Score:")
print(highest_score(scores))

The list stores all scores, the loops calculate the total and highest value, and len() helps calculate the average.