Numbers and Operators |Section 1| Celestial Warrior

1 year ago
21

1

00:00:00,269 --> 00:00:04,680

Hi again, in this lecture I'll show you

how to do math operations with numbers.

3

00:00:04,680 --> 00:00:10,200

So we're going to look at math operators.

Let's go straight away and open a Python

5

00:00:10,200 --> 00:00:16,880

section and let me write a math

expression there. 20 minus 10 divided by

7

00:00:16,880 --> 00:00:31,019

5 times 3 in the power of 2 and what we

get is 2.0. So why did I write this a

9

00:00:31,019 --> 00:00:36,239

long expression? Well because I want to

explain to you the order of operators so

11

00:00:36,239 --> 00:00:41,760

when you have multiple operators in an

expression the one to be executed

13

00:00:41,760 --> 00:00:50,910

first is the exponent, so we have 3 in

power of 2 here that will give us 9.

15

00:00:50,910 --> 00:00:56,120

So power is the first to be executed and

also that is division and multiplication.

17

00:00:56,120 --> 00:01:00,210

Actually division and

multiplication are on the same level.

19

00:01:00,210 --> 00:01:06,330

We're talking about order but the one

that is first will be executed first so in

21

00:01:06,330 --> 00:01:11,640

this case division is the first one so

what will happen here is Python will

23

00:01:11,640 --> 00:01:16,500

ignore minus for now,

so it will divide 10 by 5 and it will

25

00:01:16,500 --> 00:01:30,180

give 2 then it will do 2 times 9.

So again 10 divided by 5, 2 times 9, 19.

27

00:01:30,180 --> 00:01:35,220

And then we have the rest of the operators

which could be a plus or minus so in

29

00:01:35,220 --> 00:01:45,299

this case we have minus so 20 minus 18.

We have 2.0. You'd ask why we have 2.0?

31

00:01:45,299 --> 00:01:54,509

Because 10 divided by 5 gives 2.0.

So division outputs a float in Python 3.

33

00:01:54,509 --> 00:02:00,540

If you are on Python 2, it would output

an integer. Now to make your expressions

35

00:02:00,540 --> 00:02:10,590

look better, you'd want to remove the

spaces for the power operator and also

37

00:02:10,590 --> 00:02:15,569

you do like that somehow you can read it

better,

39

00:02:15,569 --> 00:02:23,550

so 2 times 9 and then 20 minus 18 and so on.

You get the idea.

41

00:02:23,550 --> 00:02:33,599

You get 2.0 again and now if you want to

execute the minus operator first

43

00:02:33,599 --> 00:02:38,569

you'd want to put that inside brackets.

So why did we get 18? Well because 20

45

00:02:43,890 --> 00:02:52,940

minus 10 gives 10 and then 10 divided by

5 gives 2 and then 2 times 9 gives 18.

47

00:02:52,940 --> 00:03:02,459

That's the idea. And then you could also do

this, put these in brackets and what

49

00:03:02,459 --> 00:03:13,890

would happen here is you know 10 here,

15 here in the power of 2, so 15 in the

51

00:03:13,890 --> 00:03:20,459

power of 2, and then 10, so 10 divided by

15 in the power of 2. Let's see what we get.

53

00:03:20,459 --> 00:03:25,920

Yeah we got that, so let's see if I was

55

00:03:25,920 --> 00:03:31,260

Right.

15 in the power of 2 we get 225.

57

00:03:31,260 --> 00:03:42,510

And then we got 10 on the other side, so 10

divided by 225. We get that number.

59

00:03:42,510 --> 00:03:46,349

So whenever you want to change the

order of operators, you should use

61

00:03:46,349 --> 00:03:53,549

brackets and so I hope you get the idea

and please try this out, so try to do a

63

00:03:53,549 --> 00:03:57,569

few operations with numbers to get used to it.

And yeah, I'll talk to you later.

65

00:03:57,569 --> 00:04:00,379

Thanks.

Loading comments...