All language subtitles for 050 [Interactive Coding Exercise] High Score.en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

1

So now that you've gotten a taste for for loops,

2

it's time to complete another challenge

3

which is going to stretch you a little bit further. Head over to day 5.2 highest

4

score,

5

and we're going to get a list of students scores,

6

and it's a list of numbers again.

7

The idea is that you are going to write some code

8

that's going to output the highest score in the class.

9

So you're going to look through this list

10

using a for loop and figure out which of the scores inside the list is the

11

highest value. Now we can see pretty much at a glance that inside this list,

12

91 is the highest. But remember that when you test your code,

13

you won't be able to see the input. So you won't be able to cheat that way.

14

Instead, you have to do this using code. Now, just as in the last lesson

15

I mentioned that Python has some pretty useful functions that help us do a lot

16

of these commonly needed things very easily

17

such as the sum and the len functions, well, in this case,

18

there's actually something called the max function.

19

So if we pass a list,

20

let's say the student_scores list into a max function

21

and then I go ahead and print out the maximum value from my list of student_

22

scores. So let's run this code and I'm going to use the example input,

23

so a bunch of numbers separated by a space, and hit enter,

24

and you can see it tells me that 91 is the highest value.

25

Now there's also the min function

26

which basically will give me the lowest value inside a particular list,

27

which in this case is 55, but that's too easy.

28

I don't want you to use the max or the min functions. Instead,

29

you have to use what you've learned about for loops to replicate the underlying

30

functionality of this max function.

31

Because people tend to use Python to do a lot of data manipulation,

32

to do a lot of mathematical calculations.

33

It has a lot of these convenient functions for you.

34

But let's say you moved to a different language and you work on something else,

35

then these might not exist.

36

So understanding the underlying logic and being able to write out the code

37

using things that every programming language has like the for loop will mean

38

that you will become a much, much better programmer in the process.

39

So try and replicate the functionality of the max function and the output should

40

have the words

41

The highest score in the class is : and then a space and then the actual max

42

value. So this is what should happen. Pause the video now,

43

and have a think about how you would write your code in order to get hold of the

44

maximum value from a list.

45

All right. So did you manage to complete this challenge? If not,

46

and if you want to see how I do it, then continue watching along.

47

The first thing we want to do is we probably want to get a hold of each of the

48

scores inside our list of student scores.

49

So I'm going to write something like for score in student_scores,

50

so again,

51

keeping that convention of singular from plural. Now,

52

inside the loop, what can I do? Now

53

let's say I had a variable called the highest_score,

54

and I'm going to start it off as zero. And then inside my loop,

55

I can use an if statement to check, well is the current score that I'm looping

56

through greater than the highest score that I've got.

57

Well then if so, that means that this current score should actually be the

58

highest score.

59

So I can set my highest_score to equal,

60

single equals mean assign, double equals mean checking, remember?

61

And this loop will continue running until I've checked through all the scores

62

inside my student_scores,

63

and I've got the highest score stored inside this variable.

64

So now I can go ahead and print the sentence;

65

The highest score is this particular value.

66

So I'm going to use an f-string to insert my highest_score variable inside here.

67

And if I run my code and use this example input, then you can see

68

it tells me the high score in the class is 91,

69

which matches exactly with the example output. Now,

70

if you're at all confused about how this code works,

71

then I recommend again, pasting it into Thonny like this.

72

So you've got a list of scores and then you've got the code in the solution and

73

click on debug.

74

And you can see how we actually step through each of the stages where we start

75

off with a highest score being equal to zero, so that's where it is,

76

and then we continue into the loop where we go through each of the scores inside

77

the student_scores, so the first one is going to be 78.

78

So now we've got this variable score which is tied to the value of 78.

79

And then we go and check if the score,

80

which is 78, is greater than the highest score, which is zero. Well,

81

that's obviously true, right? So if that's true,

82

then it's going to carry out the next line of code,

83

which is that the highest score is now equal to score.

84

So now notice how this highest_score variable is going to update to the first

85

value because 78 is greater than zero.

86

Now we go back to the start of the loop and we go to the next value,

87

65. And 65 is now checked against the highest score. Is 65 greater than 78?

88

Well, no, that's not true. So this is false.

89

And so the highest score is left alone. And we continue back to the next value.

90

So now our score is equal to 89 and our highest_score is still equal to 78. Is 89

91

greater than 78? Yes.

92

So now we reset the highest_score to the new value,

93

which is 89.

94

And it continues this loop until it gets to the end and it's found the highest

95

value and it prints it out into the console.

96

Play around with the debug and step through each of the stages to see how it

97

works and compare it with what's happening with each of the variables on the

98

right. This is a really,

99

really useful way of wrapping your head around all of this complex,

100

looping and conditionals. And once you've understood everything that's going on,

101

then you can continue to the next lesson where we're going to talk about another

102

type of for loop, the for loop using a range operator.

103

So for all of that and more, I'll see you in the next lesson.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.