In this exercise, you're going to write some
code to create a program that works
out the highest number from a list of numbers.
The scenario is that you work at a school
and your students have come in with all of these scores
and you're going to use Python to figure
out what is the highest score that a given student achieved.
Essentially, what we're doing is we are
replicating the Python max() function
but you must not use the max() function.
Instead, I want you to use a for loop to create
this functionality yourself
and practice the use of for loops.
Take a look at the Example Input
and see what the Example Output is expected to be.
Make sure you match the formatting and the words exactly.
Give this challenge a go now.
So lines two to four have been already written for you
and this just grabs each of the numbers
in the Input and puts them into a list called scores.
Now what you are doing is writing a for loop
in order to track the highest score.
The first thing we're doing is we're creating
a variable called highest_score and setting it to 0.
Next, we write our for loop to loop
through each of the scores in our list of student_scores.
While the loop is running, inside the for loop
we check for a condition,
we use the if statement to check
if the current_score that we are looping
through is greater than the current highest_score.
Now, the first time this loop runs
of course it's going to be greater
because the higher score is 0
so unless somebody had a negative score
then that is going to be the highest score.
Each time we loop through the for loop, we keep checking
against the highest_score variable and making sure
that we store the highest value that we come across.
So if the condition is true, the current score is greater
than the highest score that we previously had,
we set the highest_score to that current score.
And then finally we use a print statement to print
out, "The highest score in the class is:"
and then we insert the highest_score using an f-string.
And because this print statement happens
after the for loop is completed,
notice the indentation of the print statement,
making sure this line is not indented to
inside the for loop,
then this print statement is going to be carried
out once all the scores have been checked
in that list of student scores.