Due 11/2 at 11:59pm
Video games often track player scores. Given a list of scores, how do you find the best one? The worst one? The average? In this project you will write algorithms — step-by-step procedures — and put each one in its own function.
Your program must meet the following specifications:
find_highest that takes a list of numbers and returns the highest scorefind_lowest that takes a list of numbers and returns the lowest scorefind_average that takes a list of numbers and returns the average scorefor loop to look at every scoreIn find_highest and find_lowest, start by assuming the first score is the answer, then update it when you see a higher or lower score. In find_average, add up every score, then divide the total by how many scores are in the list:
average = total / len(scores)
A list stores multiple values in order. You can access items by index (starting at 0):
scores = [85, 92, 78, 95, 88]
print(scores[0]) # 85
print(scores[3]) # 95
print(len(scores)) # 5
A for loop lets you do something once for each item in a list:
scores = [85, 92, 78]
for score in scores:
print(score)
This prints each score on its own line.
Here is a starting point. Fill in the TODO comments to meet the specifications above!
def find_highest(scores):
# Start by assuming the first score is the highest
highest = scores[0]
# TODO: Compare each score against the running highest;
# if it is greater, make it the new highest!
for score in scores:
pass
# TODO Return the highest score
def find_lowest(scores):
# TODO
pass
def find_average(scores):
# TODO
pass
# Print a list of scores, then computes and prints
# highest, lowest and average scores for the list
def evaluate_list(scores):
print(f'{str(scores):^24}')
print('-' * 24)
print(f'Highest:{find_highest(scores):>16}')
print(f'Lowest: {find_lowest(scores):>16}')
print(f'Average:{find_average(scores):>16.1f}')
def main():
evaluate_list([68, 1, 4, 60, 44])
print()
evaluate_list([91, 86, 97, 66, 19])
print()
evaluate_list([48, 0, 27, 60, 100])
print()
main()
When your functions are implemented properly, you should see the following program output:
[68, 1, 4, 60, 44]
------------------------
Highest: 68
Lowest: 1
Average: 35.4
[91, 86, 97, 66, 19]
------------------------
Highest: 97
Lowest: 19
Average: 71.8
[48, 0, 27, 60, 100]
------------------------
Highest: 100
Lowest: 0
Average: 47.0
When you’re happy with your high score finder, upload the .py file to ThinkWave.