1
00:00:00,450 --> 00:00:02,460
In this exercise, you're going to write some

2
00:00:02,460 --> 00:00:05,160
code to create a program that works

3
00:00:05,160 --> 00:00:09,930
out the highest number from a list of numbers.

4
00:00:09,930 --> 00:00:12,870
The scenario is that you work at a school

5
00:00:12,870 --> 00:00:16,290
and your students have come in with all of these scores

6
00:00:16,290 --> 00:00:18,300
and you're going to use Python to figure

7
00:00:18,300 --> 00:00:21,990
out what is the highest score that a given student achieved.

8
00:00:21,990 --> 00:00:24,330
Essentially, what we're doing is we are

9
00:00:24,330 --> 00:00:28,020
replicating the Python max() function

10
00:00:28,020 --> 00:00:30,600
but you must not use the max() function.

11
00:00:30,600 --> 00:00:34,770
Instead, I want you to use a for loop to create

12
00:00:34,770 --> 00:00:36,570
this functionality yourself

13
00:00:36,570 --> 00:00:38,940
and practice the use of for loops.

14
00:00:38,940 --> 00:00:41,070
Take a look at the Example Input

15
00:00:41,070 --> 00:00:44,910
and see what the Example Output is expected to be.

16
00:00:44,910 --> 00:00:48,782
Make sure you match the formatting and the words exactly.

17
00:00:48,782 --> 00:00:51,123
Give this challenge a go now.

18
00:00:58,350 --> 00:01:02,100
So lines two to four have been already written for you

19
00:01:02,100 --> 00:01:05,190
and this just grabs each of the numbers

20
00:01:05,190 --> 00:01:09,273
in the Input and puts them into a list called scores.

21
00:01:10,140 --> 00:01:13,200
Now what you are doing is writing a for loop

22
00:01:13,200 --> 00:01:15,750
in order to track the highest score.

23
00:01:15,750 --> 00:01:17,490
The first thing we're doing is we're creating

24
00:01:17,490 --> 00:01:21,600
a variable called highest_score and setting it to 0.

25
00:01:21,600 --> 00:01:25,080
Next, we write our for loop to loop

26
00:01:25,080 --> 00:01:30,080
through each of the scores in our list of student_scores.

27
00:01:30,690 --> 00:01:34,110
While the loop is running, inside the for loop

28
00:01:34,110 --> 00:01:36,450
we check for a condition,

29
00:01:36,450 --> 00:01:38,370
we use the if statement to check

30
00:01:38,370 --> 00:01:40,985
if the current_score that we are looping

31
00:01:40,985 --> 00:01:45,210
through is greater than the current highest_score.

32
00:01:45,210 --> 00:01:46,800
Now, the first time this loop runs

33
00:01:46,800 --> 00:01:48,500
of course it's going to be greater

34
00:01:49,423 --> 00:01:50,310
because the higher score is 0

35
00:01:50,310 --> 00:01:52,560
so unless somebody had a negative score

36
00:01:52,560 --> 00:01:56,220
then that is going to be the highest score.

37
00:01:56,220 --> 00:02:00,030
Each time we loop through the for loop, we keep checking

38
00:02:00,030 --> 00:02:02,970
against the highest_score variable and making sure

39
00:02:02,970 --> 00:02:06,450
that we store the highest value that we come across.

40
00:02:06,450 --> 00:02:10,229
So if the condition is true, the current score is greater

41
00:02:10,229 --> 00:02:13,710
than the highest score that we previously had,

42
00:02:13,710 --> 00:02:16,757
we set the highest_score to that current score.

43
00:02:16,757 --> 00:02:21,550
And then finally we use a print statement to print

44
00:02:22,471 --> 00:02:23,820
out, "The highest score in the class is:"

45
00:02:24,698 --> 00:02:27,480
and then we insert the highest_score using an f-string.

46
00:02:27,480 --> 00:02:30,420
And because this print statement happens

47
00:02:30,420 --> 00:02:33,442
after the for loop is completed,

48
00:02:33,442 --> 00:02:36,170
notice the indentation of the print statement,

49
00:02:36,170 --> 00:02:37,620
making sure this line is not indented to

50
00:02:37,620 --> 00:02:39,240
inside the for loop,

51
00:02:39,240 --> 00:02:41,610
then this print statement is going to be carried

52
00:02:41,610 --> 00:02:44,340
out once all the scores have been checked

53
00:02:44,340 --> 00:02:46,473
in that list of student scores.

