1
00:00:05,240 --> 00:00:09,030
Welcome to the second lesson

2
00:00:09,030 --> 00:00:10,915
on programming within Python.

3
00:00:10,915 --> 00:00:12,770
We're going to do a quick recap

4
00:00:12,770 --> 00:00:14,330
of some of the math operators,

5
00:00:14,330 --> 00:00:15,890
or the arithmetic
operators that you

6
00:00:15,890 --> 00:00:17,950
can actually use
within the language.

7
00:00:17,950 --> 00:00:19,990
Some of them might
be very familiar,

8
00:00:19,990 --> 00:00:21,350
some of them might
be less familiar,

9
00:00:21,350 --> 00:00:23,850
but certainly it's
a good reminder

10
00:00:23,850 --> 00:00:25,450
of some of the things out there,

11
00:00:25,450 --> 00:00:27,530
specifically for
understanding the syntax.

12
00:00:27,530 --> 00:00:29,930
Let's go through
them. We do have

13
00:00:29,930 --> 00:00:32,210
simple expression
math expressions like

14
00:00:32,210 --> 00:00:35,580
addition and subtraction,
multiplication and division.

15
00:00:35,580 --> 00:00:40,190
All of those have specific
tokens associated with them,

16
00:00:40,190 --> 00:00:42,150
which are pretty much standard.

17
00:00:42,150 --> 00:00:44,770
But we also have calculations
like the remainder,

18
00:00:44,770 --> 00:00:47,570
the floor division,
or the exponent.

19
00:00:47,570 --> 00:00:52,010
Sometimes those might not
be as familiar and we will

20
00:00:52,010 --> 00:00:53,990
see a bit of an example of

21
00:00:53,990 --> 00:00:56,500
how those actually work
within the language,

22
00:00:56,500 --> 00:01:00,190
and it's always a
good information

23
00:01:00,190 --> 00:01:01,850
to have of some of the operators

24
00:01:01,850 --> 00:01:03,850
that you can actually
use within the language.

25
00:01:03,850 --> 00:01:08,320
Let's go through them in
the code. Here we go.

26
00:01:13,240 --> 00:01:15,990
Let's just create an environment

27
00:01:15,990 --> 00:01:17,610
in which we can actually work.

28
00:01:17,610 --> 00:01:24,480
I'm going to create a simple
variable of assumation 2-3.

29
00:01:24,940 --> 00:01:27,920
At all times as we just covered,

30
00:01:27,920 --> 00:01:30,930
you can do a print function to

31
00:01:30,930 --> 00:01:35,090
test how this variable
is in fact executed,

32
00:01:35,090 --> 00:01:36,850
and if you're having any errors

33
00:01:36,850 --> 00:01:38,960
you wouldn't see the result.

34
00:01:38,960 --> 00:01:42,210
So far so good.

35
00:01:42,210 --> 00:01:45,150
Feel free to add
more comments than

36
00:01:45,150 --> 00:01:49,565
the ones I'm doing here.

37
00:01:49,565 --> 00:01:55,880
Let's just do a simple
addition, subtraction.

38
00:01:55,880 --> 00:02:00,070
Let's call that subs equals 3-2.

39
00:02:00,070 --> 00:02:03,265
Notice that if I do no space,

40
00:02:03,265 --> 00:02:05,770
that shouldn't be a problem.

41
00:02:06,290 --> 00:02:09,850
Some people like writing
really tight code,

42
00:02:09,850 --> 00:02:11,950
and some people like spreading

43
00:02:11,950 --> 00:02:14,370
the code a little bit
more for legibility.

44
00:02:14,370 --> 00:02:16,970
Certainly that's something
that it's up to you.

45
00:02:16,970 --> 00:02:18,550
I actually do prefer having

46
00:02:18,550 --> 00:02:21,180
a little bit more
space, so readability,

47
00:02:21,180 --> 00:02:22,950
the way in which you can relate

48
00:02:22,950 --> 00:02:25,810
to your own work in programming,

49
00:02:25,810 --> 00:02:27,110
is something that I certainly

50
00:02:27,110 --> 00:02:29,250
always encourage students too.

51
00:02:29,250 --> 00:02:30,730
Make your editor your own find

52
00:02:30,730 --> 00:02:33,405
the right color
combination contrast

53
00:02:33,405 --> 00:02:35,770
and also the font
size so that you

54
00:02:35,770 --> 00:02:39,660
feel at home with your own work.

55
00:02:40,000 --> 00:02:44,820
The multiplication, and
very straightforward.

56
00:02:46,500 --> 00:02:56,260
Let's do 2*3.

57
00:02:56,260 --> 00:02:58,400
We have six here.

58
00:02:58,580 --> 00:03:01,550
Notice that for
whatever reason I

59
00:03:01,550 --> 00:03:04,120
would just capitalize this,

60
00:03:04,120 --> 00:03:06,610
like thinking that,
maybe I forgot that

61
00:03:06,610 --> 00:03:09,840
this variable was actually
spelled with a lower case m,

62
00:03:09,840 --> 00:03:12,135
and I pressed capital case.

63
00:03:12,135 --> 00:03:14,250
We're not going to
get the result.

64
00:03:14,250 --> 00:03:16,550
In other programming
environments,

65
00:03:16,550 --> 00:03:18,650
you're going to get much
more clear error message

66
00:03:18,650 --> 00:03:20,570
saying that this is
actually missing.

67
00:03:20,570 --> 00:03:24,510
But because this is mostly a
programming environment for

68
00:03:24,510 --> 00:03:27,210
graphic content and
it's not really

69
00:03:27,210 --> 00:03:30,490
meant to be Python
environment originally,

70
00:03:30,490 --> 00:03:31,950
we're not getting that message,

71
00:03:31,950 --> 00:03:34,410
but something that we'll
have to work with,

72
00:03:34,410 --> 00:03:35,610
it's a trade off between

73
00:03:35,610 --> 00:03:38,590
graphic capabilities of
what we're doing here

74
00:03:38,590 --> 00:03:41,050
versus the kind of

75
00:03:41,050 --> 00:03:43,360
information that we get in
terms of making errors.

76
00:03:43,360 --> 00:03:46,065
I like testing as I go,

77
00:03:46,065 --> 00:03:50,220
that the information I'm
creating is in fact correct,

78
00:03:50,220 --> 00:03:53,665
through a print method or
something along those lines.

79
00:03:53,665 --> 00:03:56,830
We'll see other forms of
debugging in the future.

80
00:03:56,830 --> 00:04:01,290
Let's do a few more division.

81
00:04:06,980 --> 00:04:11,620
Let's see what happens
here if I do a 3/2.

82
00:04:12,170 --> 00:04:17,460
Notice that I'm writing the
three and two as integers,

83
00:04:17,460 --> 00:04:20,150
meaning that they don't
have any decimal place.

84
00:04:20,150 --> 00:04:24,025
But the division of this
operation should be a float.

85
00:04:24,025 --> 00:04:26,085
Let's see the result of this.

86
00:04:26,085 --> 00:04:30,150
We actually get one and
that's pro incorrect.

87
00:04:30,150 --> 00:04:32,350
If we divide 3/2,

88
00:04:32,630 --> 00:04:36,225
we should get a 1.5.

89
00:04:36,225 --> 00:04:41,130
The way we determine
these variables,

90
00:04:41,130 --> 00:04:45,290
and I'm going to add a
0.0 to each one of those.

91
00:04:45,290 --> 00:04:47,790
Even just doing it to one
of them should be enough.

92
00:04:47,790 --> 00:04:51,610
But this actually signals
the program that we would

93
00:04:51,610 --> 00:04:56,435
like to consider these
variables as floats,

94
00:04:56,435 --> 00:05:01,340
so that the operation of
division doesn't end up

95
00:05:01,340 --> 00:05:04,980
removing the 0.5 that

96
00:05:04,980 --> 00:05:08,320
it's actually required for the
calculation to be correct.

97
00:05:08,320 --> 00:05:11,580
That's a little bit
of a consideration

98
00:05:11,580 --> 00:05:13,700
as we're doing some
of these operations,

99
00:05:13,700 --> 00:05:18,105
how careful we are in getting
the correct information.

100
00:05:18,105 --> 00:05:20,360
This might be a rounding
error that might

101
00:05:20,360 --> 00:05:23,810
be at the center of a
much larger calculation,

102
00:05:23,810 --> 00:05:25,620
and if for whatever reason you

103
00:05:25,620 --> 00:05:28,200
forgot to add this
decimal place,

104
00:05:28,200 --> 00:05:29,360
it might be that
you're not getting

105
00:05:29,360 --> 00:05:32,160
the right accurate result
that you're expecting.

106
00:05:32,160 --> 00:05:34,605
Let's look at the
remainder operation.

107
00:05:34,605 --> 00:05:38,895
Here we're going to
spell remainder.

108
00:05:38,895 --> 00:05:41,090
The remainder operation is done

109
00:05:41,090 --> 00:05:43,595
with the modular or
the percentage sign.

110
00:05:43,595 --> 00:05:47,670
This is an operation
that is not that common,

111
00:05:47,670 --> 00:05:50,540
but it's very useful.

112
00:05:50,960 --> 00:05:53,250
It's very useful if
you want to find

113
00:05:53,250 --> 00:05:55,270
odd and even numbers
and things like that.

114
00:05:55,270 --> 00:05:57,250
Basically what the
remainder operation is

115
00:05:57,250 --> 00:05:59,270
doing is calculating
if the two fits

116
00:05:59,270 --> 00:06:03,000
one in three, what
is the remainder?

117
00:06:03,000 --> 00:06:06,005
What is the accident, if
you want, of that division?

118
00:06:06,005 --> 00:06:08,360
In this case that would be one.

119
00:06:08,360 --> 00:06:11,765
Let's execute that
to double check.

120
00:06:11,765 --> 00:06:16,630
We have that. If we
would put a four here,

121
00:06:16,630 --> 00:06:17,850
you would see that the result of

122
00:06:17,850 --> 00:06:19,310
that operation should be zero,

123
00:06:19,310 --> 00:06:23,320
because the two feet
actually twice in four.

124
00:06:23,320 --> 00:06:26,045
Let's just close these windows.

125
00:06:26,045 --> 00:06:28,550
Whenever you're
running out of space,

126
00:06:28,550 --> 00:06:32,645
you can always create more
space for you to work here.

127
00:06:32,645 --> 00:06:37,035
Let's jump into the
final one or no,

128
00:06:37,035 --> 00:06:38,470
just we have a few more but

129
00:06:38,470 --> 00:06:41,370
we're going to cover
the floor division.

130
00:06:42,050 --> 00:06:44,790
Let's just write
it and understand.

131
00:06:44,790 --> 00:06:46,410
It's a floor division,

132
00:06:46,410 --> 00:06:49,090
and we're going to call
it a flow for now,

133
00:06:49,090 --> 00:06:57,410
and that's five with this
double backslash sign.

134
00:06:59,070 --> 00:07:01,060
Let's see the calculation.

135
00:07:01,060 --> 00:07:05,115
In this case the floor division,

136
00:07:05,115 --> 00:07:07,340
it's going to give us
that division operation

137
00:07:07,340 --> 00:07:08,900
which in this case is two,

138
00:07:08,900 --> 00:07:11,485
but it's going to
remove any remainder.

139
00:07:11,485 --> 00:07:14,710
It's going to give us
the lowest denominator.

140
00:07:14,710 --> 00:07:17,820
If we have 5.5 for instance,

141
00:07:17,820 --> 00:07:20,200
you'll see that it

142
00:07:20,200 --> 00:07:22,320
will give us to us as
a float, but in fact,

143
00:07:22,320 --> 00:07:26,430
it will still give us the floor,

144
00:07:26,430 --> 00:07:29,325
meaning the lowest value

145
00:07:29,325 --> 00:07:33,060
rounded down from
that operation.

146
00:07:33,060 --> 00:07:37,145
That's something also
quite useful to have.

147
00:07:37,145 --> 00:07:40,060
Then finally, the exponent,

148
00:07:42,270 --> 00:07:45,790
which we're going to cover here,

149
00:07:45,790 --> 00:07:53,460
it's exp = 2**3.

150
00:07:53,460 --> 00:07:55,450
Obviously, if you imagine

151
00:07:55,450 --> 00:07:57,090
we don't have a way
of writing that

152
00:07:57,090 --> 00:08:00,600
three in a very small
format adjacent to the two,

153
00:08:00,600 --> 00:08:04,120
so this is the way you would
spell out this exponent.

154
00:08:04,120 --> 00:08:08,760
You see that if I
type exp turns pink,

155
00:08:08,760 --> 00:08:10,185
that means that
there seems to be

156
00:08:10,185 --> 00:08:13,610
a keyword associated
with that variable.

157
00:08:13,610 --> 00:08:15,835
I'm going to call it expo,

158
00:08:15,835 --> 00:08:18,410
short for exponent,

159
00:08:18,740 --> 00:08:21,360
and I can double check that,

160
00:08:21,360 --> 00:08:23,745
that's in fact working.

161
00:08:23,745 --> 00:08:25,620
We have a value of eight, that

162
00:08:25,620 --> 00:08:27,750
means let's just do a comment.

163
00:08:27,750 --> 00:08:30,800
If you remember, an exponent
means that we have 2*2*2

164
00:08:30,800 --> 00:08:36,450
, that's three times.

165
00:08:36,450 --> 00:08:39,300
If we actually would
have it one more time,

166
00:08:39,300 --> 00:08:41,215
an exponent of four,

167
00:08:41,215 --> 00:08:44,630
two exponent of four,

168
00:08:46,050 --> 00:08:52,140
we would get a result of
16 as you can see here.

169
00:08:52,140 --> 00:08:54,030
These are the
arithmetic operators.

170
00:08:54,030 --> 00:08:56,450
There's a few caveats
regarding how

171
00:08:56,450 --> 00:08:58,590
you deal with variable types

172
00:08:58,590 --> 00:09:00,830
in the case of
division, for instance,

173
00:09:00,830 --> 00:09:03,150
and how there's a conversion

174
00:09:03,150 --> 00:09:06,630
made once you use
a decimal place,

175
00:09:06,630 --> 00:09:08,610
and what is the
precision that you're

176
00:09:08,610 --> 00:09:11,090
expecting and how certain
other operators in

177
00:09:11,090 --> 00:09:14,830
fact help us obtain
the result that is

178
00:09:14,830 --> 00:09:16,880
exactly what we wanted
in case we wanted

179
00:09:16,880 --> 00:09:20,325
the lower the floor
operator for instance.

180
00:09:20,325 --> 00:09:22,830
I hope this is useful.
I'll see you in

181
00:09:22,830 --> 00:09:26,930
the next lesson where we'll
continue with functions.