00:01
Okay, so in this question, what we want to do is to, we have a list of five integers and we want to print the square of each of those five integers.
00:15
So the first thing i'm going to do is i'm going to create a list of five random integers.
00:21
So in order to know that, you need to import random and create a random list.
00:29
Now, this is not a necessary step.
00:32
You could just hardcode your five integers, but just to make sure that it work for multiple lists, i'm going to create random numbers.
00:42
But if you want, you could hardcode your list.
00:44
I will show you how later.
00:47
So random list is function.
00:48
What does it do? it will create.
00:55
So random list equals random.
00:57
Dot simple range 0, 105.
01:02
What is it? it will create a list of five integers between 0 and 100.
01:14
If you wanted integers between 10 and 20, you would write 10 and 20.
01:19
And if you wanted 20 integer, you would write 20 instead of 5.
01:23
So this final number here is the number of element in the list.
01:27
And this is where you want your random numbers to be.
01:32
If you don't want a random list, you could just say integer list and simply write your number.
01:42
So let's say one, two, three, four, five.
01:46
So that would be a hard -coded list of integers.
01:57
And now how you print the square of these numbers? well, pretty simple.
02:02
You create a four loop.
02:03
It's only two lines so four and you want the square of every element so for every element in let's start with the random list or actually let's start with the hard -coded list in integer list print so we want the square right so how do we square a number in python you use a power function so you take your element and you want to the power two and that's it that's your code so let's let's try it just for fun.
02:46
So i'm going to increase the size of the console here.
02:51
So we have 1, 2, 3, 4, 5 as our integers.
02:58
And what's 1 square is 1? 2 square is 2 times 2, it's 4, 3 square is 9, 4 square is 16, 5 square is 25...