1
00:00:00,360 --> 00:00:01,380
In this exercise

2
00:00:01,380 --> 00:00:04,410
you're going to create a virtual coin toss program

3
00:00:04,410 --> 00:00:06,510
and it's randomly going to tell the user

4
00:00:06,510 --> 00:00:09,720
whether if they got "Heads" or "Tails."

5
00:00:09,720 --> 00:00:12,660
It's important that the first letter should be capitalized

6
00:00:12,660 --> 00:00:14,880
and spelled exactly as in the example

7
00:00:14,880 --> 00:00:16,680
because we're going to test for it.

8
00:00:16,680 --> 00:00:19,470
And there's many ways that you could do this,

9
00:00:19,470 --> 00:00:22,080
but to practice creating random numbers

10
00:00:22,080 --> 00:00:24,300
you're going to generate a random number,

11
00:00:24,300 --> 00:00:27,330
either a 0 or 1, and then use that number

12
00:00:27,330 --> 00:00:29,370
to print out "Heads" or "Tails"

13
00:00:29,370 --> 00:00:32,159
where 1 is Heads and 0 is Tails.

14
00:00:32,159 --> 00:00:35,700
So the Example Output should just be Heads or Tails

15
00:00:35,700 --> 00:00:38,040
and that's all there is to it.

16
00:00:38,040 --> 00:00:39,273
So have a go at this.

17
00:00:42,210 --> 00:00:44,490
So the first step to use the random module

18
00:00:44,490 --> 00:00:47,220
is to actually import the random module,

19
00:00:47,220 --> 00:00:50,680
and we do that on line one, "import random".

20
00:00:51,660 --> 00:00:55,140
And then we use a function inside the random module

21
00:00:55,140 --> 00:00:59,010
called randint(), which generates a random integer,

22
00:00:59,010 --> 00:01:00,690
a random whole number

23
00:01:00,690 --> 00:01:03,540
and we get to define what that whole number can be.

24
00:01:03,540 --> 00:01:06,600
And we do that by writing 0, 1

25
00:01:06,600 --> 00:01:09,120
so either 0 or 1.

26
00:01:09,120 --> 00:01:12,450
And then we assign the value that gets generated

27
00:01:12,450 --> 00:01:14,550
from this random coin-toss

28
00:01:14,550 --> 00:01:17,553
into a variable which I've called random_side.

29
00:01:18,720 --> 00:01:20,220
Now finally, because we know

30
00:01:20,220 --> 00:01:24,060
that the random_side can only be either 0 or 1,

31
00:01:24,060 --> 00:01:26,760
we do a conditional check where we check to see

32
00:01:26,760 --> 00:01:29,370
if it is one then we're going print out "Heads",

33
00:01:29,370 --> 00:01:31,923
and if it's zero we're going to print out "Tails".

