WEBVTT

00:00.080 --> 00:07.820
In this new activity, you will take an input from the user, let's say 0 or 1, and if the user gives

00:07.820 --> 00:09.860
you zero, you turn off the LED.

00:09.890 --> 00:13.400
If the user gives you one, you turn on the LED.

00:13.700 --> 00:21.380
So here zero means turn off and then one means turn on.

00:21.380 --> 00:27.410
And you're going to use the input function okay that we have seen previously.

00:27.410 --> 00:33.440
So you will have first to set up the LED with the Gpio zero module like we did in the previous lesson.

00:33.440 --> 00:39.110
And then to get the number from the user you can use the input with a nice input message.

00:39.110 --> 00:43.160
So you can put a message here so the instruction is clear.

00:43.160 --> 00:51.170
Then you can put this input result inside a variable for example user choice like this.

00:51.170 --> 00:55.070
And of course don't forget to cast to an int.

00:55.070 --> 01:01.760
So the whole thing because what you're going to get is a string that you want to cast to an int, okay,

01:01.760 --> 01:03.320
to get 0 or 1.

01:03.320 --> 01:09.190
So after you get the input, what you can do as an additional step is to validate Date that input.

01:09.460 --> 01:10.750
Why we validate that input?

01:10.750 --> 01:13.750
Because we are expecting 0 or 1.

01:13.750 --> 01:20.320
But if the user gives you -1 or 10 or any other number, well, that's not valid.

01:20.320 --> 01:23.110
You want to have exactly 0 or 1.

01:23.110 --> 01:25.030
So if it's zero you turn off.

01:25.030 --> 01:26.440
If it's one, you turn on.

01:26.440 --> 01:32.650
If it's any other value, you're going to print an error message and you're going to exit the program.

01:32.650 --> 01:36.190
To exit the program, you also have this keyword exit.

01:36.250 --> 01:42.700
So if I write exit and the Python interpreter reaches that line, then it's just going to exit from

01:42.700 --> 01:46.210
the program, even if I have additional instructions after that.

01:46.210 --> 01:54.340
So if I have anything else, for example minus six then we're gonna print a log and exit.

01:54.340 --> 01:57.790
So not just minus six, it's just an example but any other number.

01:57.790 --> 02:03.400
And well, after you turn off or you turn on, maybe you wait for two seconds.

02:03.430 --> 02:03.610
Okay.

02:03.640 --> 02:07.180
So you can wait for two seconds before you finish the program.

02:07.180 --> 02:08.650
And that's basically it.

02:08.680 --> 02:08.950
Okay.

02:08.980 --> 02:13.630
So with this you will practice with the LED but also with conditions.

02:13.660 --> 02:14.050
All right.

02:14.080 --> 02:16.870
Now I will see you in the next lesson for the solution.
