Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
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.