All language subtitles for 040 [Interactive Coding Exercise] Random Exercise.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
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

Now, if you head over to the course resources, you'll be able to find a link to this first code exercise.

2

And the idea is that you're going to create basically a virtual coin-toss program so that when you run

3

the code, it should give you tails or heads depending on which random number was generated.

4

Try to use what you've learned in the previous lesson to complete this challenge.

5

So pause the video now and give that a go.

6

All right, let's go through the solution together.

7

So first, make sure you've forked your copy of the exercise so that it's under your own username, and

8

then we're going to go to main.py where we always write our code.

9

Now, in order to use the random module, we first have to import it.

10

So the module is called random.

11

So we write import random. And now using the random module, we can now tap into randint, which will

12

generate a random integer between a starting number and a ending number

13

and it's inclusive of both numbers.

14

So let's call this the random_side.

15

And using this random_side, we can use an if statement to check well if the random side that was

16

generated is equal to one, well, in that case, that means we should print that we generated heads.

17

So that's the part of the coin which normally shows a person's face.

18

Now we can use else to catch the situation where we get a zero, and in this case, we'll print tails instead.

19

So that's all there is to it.

20

And of course, as always, there are many, many ways that you could solve this challenge.

21

And if you're creative or if you looked around and you found a different way, then that's great.

22

But this is how we would do it using what we learned in the previous lesson.

23

So how did you get on with it? If you got stuck or if you forgot how to do certain things or if some

24

parts of your code didn't work or if you had errors, then this is the time to go back and fix it so

25

that you actually understand what's going on and we can proceed.

26

So once you're done, head over to the next lesson

27

and we're going to learn about Python lists.

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