All language subtitles for 053 [Interactive Coding Exercise] The FizzBuzz Job Interview Question.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
ko Korean
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

All right guys, I've got a fun coding challenge for you today,

2

and it is a problem called fizzbuzz.

3

Now this is probably one of the most asked questions at interviews for

4

programmers because it tests the way that you think,

5

and it allows the interviewer to see how you use your logic to solve a problem.

6

And the problem we're going to tackle is a children's game called

7

Fizzbuzz. Last time I checked the programmatic solution was actually up on

8

Wikipedia.

9

So I recommend reading the Wikipedia article only after you've solved this

10

Programming challenge. The rules of fizzbuzz are really simple.

11

Basically, you have a bunch of kids who sit around in a circle and going

12

clockwise. The first kid says 1, the second kid says 2.

13

But then when a kid encounters a number that's fully divisible by three,

14

then instead of saying that number, he's going to say Fizz.

15

And when the number is divisible by five,

16

instead of saying the number, they should say Buzz.

17

And if the number is divisible by both three and five, for example, 15,

18

then they should say Fizzbuzz.

19

So your program is going to replicate this for all the numbers up to and

20

including a hundred. To start off, it will probably look something like this.

21

It's going to print one, and then on the next line

22

it will print two and then fizz,

23

because three is divisible by three. And then four,

24

and then five is divisible by five so it's a buzz.

25

And then six is fizz because it's divisible by three and so on and so forth.

26

This is what your program has to do. Take a look at the instructions,

27

make sure that you understand what it is that your program has to do

28

and then pause the video and try to give this a go.

29

All right. So the first thing we have to do is to create a range, right?

30

So let's say that for number in range, and our range is between 1 and 100,

31

so we have to include 101 in here.

32

And what we want to do is we want to check whether if the number's divisible by

33

three, divisible by five,

34

or if it's divisible by both three and five.

35

Now we could write our code by doing this in order, right? We could say

36

if number % 3 is equal to zero,

37

then it's divisible

38

by three.

39

So you might think that you could write the code like this,

40

but there is a crucial problem in the logic here

41

namely that we know that the if, elif, else statements will stop

42

once it's found one statement that's true. For example,

43

if we take the number to be 15,

44

15 divided by three is equal to zero

45

so it's going to carry out whatever instruction is inside this if statement

46

and then it's going to be done with it. It's going to skip this one

47

and crucially, it's going to skip this one

48

which is what we really need. Instead of structuring our code like this,

49

what you might have done and what you should've done is in fact,

50

have this at the top.

51

So first check if it's divisible by three and by five,

52

and then if that is not true,

53

then check to see if it's divisible by five and then divisible by three or the

54

other option works as well.

55

You could do it like this. Because these two have no overlap in terms of the

56

results and then it doesn't really matter.

57

So now we can finally write our code because we can say, well,

58

if the number that we're currently encountering is divisible by both three and

59

five, then we have to print Fizzbuzz.

60

If it's only divisible by three, then we're going to print fizz.

61

And if it's only divisible by five, then we're going to print buzz.

62

All right.

63

Now that still leaves the remaining numbers, right?

64

Because the remaining numbers

65

which don't fit any of the criteria should just be printed out as the number.

66

We can catch that quite easily with an else statement that catches basically every

67

other number, in which case, we're just going to print the number.

68

So now, if I go ahead and run this code,

69

then you can see that all the way from 1 to 100,

70

it's been able to work out which ones are fizz, which ones are buzz,

71

and which ones are fizzbuzz. How did you get on with it?

72

If you got stuck or if you don't understand why this logic matters,

73

then I want you to try both versions that I showed you and see it

74

step-by-step using the Thonny program just as we did before.

75

That way you can visualize what's actually happening in terms of the logic and

76

how it's flowing from one step to the next, to the next. Now,

77

once you've done that, then go back to your exercise and try to complete it.

78

It's really, really important that you don't just say, "Oh yeah, I understand

79

now." It's a really good idea to make sure that your code actually works at the

80

end of the day and to write the code yourself. Today

81

we've learned all about loops and we're going to apply it in our final project.

82

So that's what's waiting up for you in the next lesson.

83

So head over that once you're ready.

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