1
00:00:05,580 --> 00:00:08,100
Welcome back everyone to this lecture on numbers.

2
00:00:09,430 --> 00:00:13,480
As you previously mentioned there's two main number types in Python that we're going to be working with.

3
00:00:13,570 --> 00:00:17,920
And those are integers which are whole numbers and floating point numbers which are numbers of a decimal

4
00:00:17,920 --> 00:00:18,410
point.

5
00:00:18,610 --> 00:00:22,660
Let's explore just basic math with Python how we can treat Python as a calculator.

6
00:00:22,660 --> 00:00:27,280
And then after that for the second half of this lecture we're going to discuss and explore how we can

7
00:00:27,280 --> 00:00:29,290
create variables and assign them values.

8
00:00:29,440 --> 00:00:31,080
So let's head over to the text editor.

9
00:00:31,180 --> 00:00:31,560
All right.

10
00:00:31,570 --> 00:00:32,430
Open up Adam.

11
00:00:32,440 --> 00:00:34,290
I have an untitled file here.

12
00:00:34,480 --> 00:00:39,670
I need to say this as a PI file in order for Adam to understand it it's a python script so I can run

13
00:00:39,670 --> 00:00:40,300
it.

14
00:00:40,330 --> 00:00:47,110
So try this out in a say file then select Save As and underneath my desk top flask examples what I'm

15
00:00:47,110 --> 00:00:51,080
going to do is just say this as my example.

16
00:00:51,220 --> 00:00:55,630
Pi Pi is the extension for python files.

17
00:00:55,630 --> 00:01:01,420
Ok so now I see my example that pi and I'm going to quickly write some code here prince which will actually

18
00:01:01,420 --> 00:01:03,980
display the output of something if I don't have print.

19
00:01:04,000 --> 00:01:07,060
That means when I run the dot PI file I mean that see the output.

20
00:01:07,060 --> 00:01:09,850
So let's say it prints hello world.

21
00:01:09,850 --> 00:01:11,990
So that's a string which you're going to get on later.

22
00:01:12,100 --> 00:01:17,410
But for right now just go ahead and say print open print sees either single or double quotes and then

23
00:01:17,440 --> 00:01:18,300
hello world.

24
00:01:18,430 --> 00:01:22,100
Single or double quotes make sure they match and then print CS OK.

25
00:01:22,360 --> 00:01:25,880
And then over here at the bottom I'm going to open up a new terminal.

26
00:01:26,000 --> 00:01:30,920
If you don't have this ability to open up a new terminal go back and check out our installation lecture

27
00:01:30,920 --> 00:01:31,880
and set up lecture.

28
00:01:31,940 --> 00:01:36,440
We cover the installation of python and adding this terminal to Adam there.

29
00:01:36,800 --> 00:01:37,220
OK.

30
00:01:37,340 --> 00:01:41,770
So make sure you're in the same location right here at your command line as you originally were.

31
00:01:41,780 --> 00:01:47,210
When you say the file so under-class examples my file is there in order to run this all I need to do

32
00:01:47,390 --> 00:01:51,600
is say Python space and then the name of the file.

33
00:01:51,650 --> 00:01:57,720
In my case it's called My example the PI I hit enter and now as the output I should see whatever it

34
00:01:57,720 --> 00:01:58,400
was printing.

35
00:01:58,490 --> 00:01:59,430
Hello world.

36
00:01:59,460 --> 00:01:59,910
OK.

37
00:02:00,020 --> 00:02:00,730
Perfect.

38
00:02:00,740 --> 00:02:05,210
If you have any issues again not seeing this little plus button in the lower left hand corner or maybe

39
00:02:05,210 --> 00:02:09,830
you haven't set up python yet go back to the very beginning check up our installation and setup lecture.

40
00:02:09,830 --> 00:02:14,180
We cover all that stuff and we actually have a time set for you so you can head forward in that video

41
00:02:14,270 --> 00:02:15,100
and check it all out.

42
00:02:15,320 --> 00:02:15,780
OK.

43
00:02:15,950 --> 00:02:21,260
With that being said and it's discussed now it's just very basic Python essentially how to do very basic

44
00:02:21,260 --> 00:02:22,020
math.

45
00:02:22,460 --> 00:02:27,420
So for example if we ever want to do addition and for this I'm actually going to zoom in a lot more.

46
00:02:27,440 --> 00:02:28,130
There we go.

47
00:02:28,130 --> 00:02:31,060
And let me clear my screen.

48
00:02:31,250 --> 00:02:31,800
OK.

49
00:02:32,120 --> 00:02:36,590
So if I ever want to do math such as Ed. I can say two plus one.

50
00:02:36,650 --> 00:02:39,330
So if I run that I get back three.

51
00:02:39,500 --> 00:02:46,140
If you ever want to do division that's going to be one forward slash to if you save that and you were

52
00:02:46,150 --> 00:02:47,970
to run that you'd get back 0.5.

53
00:02:47,970 --> 00:02:51,700
Notice how this is now a floating point even though these two were integers.

54
00:02:51,930 --> 00:02:54,210
And then we can also do subtraction.

55
00:02:54,210 --> 00:02:57,060
So one minus two that should give us a negative one.

56
00:02:57,270 --> 00:03:01,710
And there it is negative 1 is the output multiplication is an asterix.

57
00:03:01,710 --> 00:03:04,640
So we can say it 1 times 3.

58
00:03:05,030 --> 00:03:06,580
Or let's say three times three.

59
00:03:06,660 --> 00:03:07,950
So it's more obvious.

60
00:03:08,010 --> 00:03:12,010
So we'll save that three times three and we get back 9 as a result.

61
00:03:12,030 --> 00:03:13,300
So it makes sense.

62
00:03:13,320 --> 00:03:17,850
Keep in mind that if I didn't have the print statement here and I just said three times three and I

63
00:03:17,850 --> 00:03:21,990
tried to run this it would have no problem running it you just wouldn't see the output.

64
00:03:21,990 --> 00:03:27,150
So again in order to see the output we should be printing things so Prince overprint sees whatever the

65
00:03:27,150 --> 00:03:30,930
thing is and then enclose princes division we already went over.

66
00:03:30,960 --> 00:03:35,400
If you ever want to do something to the power for instance if I want to do that power three it's just

67
00:03:35,400 --> 00:03:36,290
to Asterix in a row.

68
00:03:36,320 --> 00:03:41,580
So two to the power of three I save that I run that it's going to be two times two times two.

69
00:03:41,580 --> 00:03:43,110
So in that case it's eight.

70
00:03:43,500 --> 00:03:48,180
And the last thing I want to mention here is the order of operations actually followed by Python.

71
00:03:48,450 --> 00:03:50,110
So I get to do that through an example.

72
00:03:50,550 --> 00:03:56,810
I'll say two plus ten times ten plus three.

73
00:03:56,820 --> 00:04:02,010
So Python is going to follow your standard order of operations which means multiplication here is going

74
00:04:02,010 --> 00:04:04,460
to happen first before this addition.

75
00:04:04,500 --> 00:04:08,750
So when I run this it's going to say OK ten times ten is one hundred.

76
00:04:08,760 --> 00:04:10,080
And then it's going to add them all up.

77
00:04:10,080 --> 00:04:13,550
So two plus 100 plus three which is 1 0 5.

78
00:04:13,740 --> 00:04:14,390
But let's imagine.

79
00:04:14,400 --> 00:04:19,340
I want to add this number first and then add these two numbers first and then multiply that result.

80
00:04:19,560 --> 00:04:25,800
Well I use parentheses to actually dictate the order of operations I want so I can wrap these in parentheses

81
00:04:26,190 --> 00:04:27,810
just like you would for normal math.

82
00:04:28,140 --> 00:04:32,550
Let's wrap these guys in princes and then we were going to add one more set of princes because that's

83
00:04:32,610 --> 00:04:34,480
outside that a prince is for Prince.

84
00:04:34,530 --> 00:04:39,780
So now I'm going to say OK add two plus 10 first then add templates 3 and then multiply these guys for

85
00:04:39,780 --> 00:04:40,800
the result.

86
00:04:40,800 --> 00:04:44,800
So I say run it and I get back 156 this time.

87
00:04:44,970 --> 00:04:45,220
OK.

88
00:04:45,240 --> 00:04:47,050
That should have been a very straight for and pretty basic.

89
00:04:47,080 --> 00:04:49,500
It's just how to do basic arithmetic with python.

90
00:04:49,500 --> 00:04:51,390
A lot of it been pretty intuitive.

91
00:04:51,390 --> 00:04:53,380
Now let's talk about variable assignments.

92
00:04:53,550 --> 00:04:57,660
OK let's take a quick dive into variable assignments in Python.

93
00:04:57,660 --> 00:05:01,770
So we just saw how to work with numbers but often we're asking ourselves well what do these numbers

94
00:05:01,770 --> 00:05:02,880
actually represent.

95
00:05:02,880 --> 00:05:08,160
I'm just writing two or three will to of one or three of what is actually a pretty nice if I could assign

96
00:05:08,160 --> 00:05:12,930
these data types a variable name that I can easily reference them later on in our code.

97
00:05:13,170 --> 00:05:18,150
For example instead of just having to I could say the variable my underscore dogs is equal to two.

98
00:05:18,270 --> 00:05:19,820
And then I could reference that variable name.

99
00:05:19,860 --> 00:05:26,680
My dogs throughout my script now there are a couple of rules for choosing a variable name variable names

100
00:05:26,680 --> 00:05:28,420
that cannot start a number.

101
00:05:28,420 --> 00:05:30,250
There can also be no spaces in the name.

102
00:05:30,250 --> 00:05:35,290
Instead you should use an underscore and you can't use any of these special symbols such as an exclamation

103
00:05:35,290 --> 00:05:37,320
mark or question mark or a dollar sign.

104
00:05:37,330 --> 00:05:38,760
So none of those symbols are allowed.

105
00:05:38,800 --> 00:05:43,480
Essentially you just be using lower case letters and then underscore and you can also use numbers as

106
00:05:43,480 --> 00:05:49,170
long as they're not the first letter or character in the variable name.

107
00:05:49,170 --> 00:05:53,170
Now there's also best practices for variable names and this is known as pep 8.

108
00:05:53,340 --> 00:05:57,110
So in general it's considered best practice that the names are all lowercase.

109
00:05:57,210 --> 00:05:59,410
It'll still work even if they're not lowercase.

110
00:05:59,430 --> 00:06:02,910
It's just a convention so that when you're reading someone else's code or someone else is reading your

111
00:06:02,910 --> 00:06:06,790
code it follows the same sort of basic convention or best practice.

112
00:06:06,810 --> 00:06:12,270
You should also avoid using words that have a special meaning in Python such as list or as TR.

113
00:06:12,270 --> 00:06:17,280
Often there are built in variables that are already used within Python and will be going through them

114
00:06:17,310 --> 00:06:21,850
throughout the course but a very common on that beginners often mistake is using list.

115
00:06:21,870 --> 00:06:27,430
So don't use that as a variable name because it's actually already built into Python.

116
00:06:27,540 --> 00:06:31,410
The last thing I want to mention is that Python actually uses dynamic typing.

117
00:06:31,410 --> 00:06:36,390
This means you can reassign variables to different data types and this makes Python very flexible in

118
00:06:36,390 --> 00:06:41,370
assigning data types and it's actually different than other languages that are what is known as statically

119
00:06:41,370 --> 00:06:42,110
typed.

120
00:06:42,120 --> 00:06:47,100
So let me quickly show you the difference between statically typed and dynamic typed.

121
00:06:47,440 --> 00:06:53,020
So let's imagine somewhere in my Python script maybe at the top I say my underscore dogs is equal to

122
00:06:53,020 --> 00:06:53,500
two.

123
00:06:53,530 --> 00:06:58,180
And then there's a bunch of code and then later at the end I say all right same variable name my underscore

124
00:06:58,180 --> 00:07:02,740
dog is not equal to what is known as a list of Samie and Franki.

125
00:07:02,740 --> 00:07:06,790
Python isn't going to complain that you suddenly change an integer into a list.

126
00:07:06,820 --> 00:07:08,450
That's totally OK in Python.

127
00:07:08,530 --> 00:07:11,910
You don't have to specify beforehand what my dogs was going to be.

128
00:07:11,920 --> 00:07:14,820
You'd have to say OK this is going to be integer or this is going to be a list.

129
00:07:14,980 --> 00:07:17,600
That's not always the case in other programming languages.

130
00:07:17,620 --> 00:07:20,190
So this is known as they Nemec typing in Python.

131
00:07:20,200 --> 00:07:24,940
It makes it really easy to code things really fast but it also leaves the potential for mistakes to

132
00:07:24,940 --> 00:07:25,330
be done.

133
00:07:25,360 --> 00:07:27,700
So just keep that in mind there is a tradeoff here.

134
00:07:28,740 --> 00:07:31,340
So again that can produce an error in other languages.

135
00:07:31,590 --> 00:07:37,030
So something that was statically typed for example to C++ you'd have to add the clear first integer.

136
00:07:37,050 --> 00:07:39,260
My dog is equal to one semi-colon.

137
00:07:39,390 --> 00:07:43,940
And then if you try to reassign my dog to something that wasn't an integer that would result in an error.

138
00:07:43,950 --> 00:07:45,770
So that's called static typing.

139
00:07:45,780 --> 00:07:50,760
However again Python doesn't use static typing Toney's dynamic typing which is why it's so popular for

140
00:07:50,760 --> 00:07:53,480
beginners and it's easy to learn.

141
00:07:53,510 --> 00:07:57,980
So again the pros of dynamic typing it's very easy to work with has faster development time.

142
00:07:57,980 --> 00:07:59,660
The cons of dynamic typing.

143
00:07:59,660 --> 00:08:02,000
It may result in bugs for unexpected data types.

144
00:08:02,010 --> 00:08:03,420
They need to be aware of that type.

145
00:08:03,470 --> 00:08:07,720
All you need to do is use that builtin type function which will go over in future lectures.

146
00:08:07,890 --> 00:08:13,550
OK so let's get an idea of all of this together by jumping over back to the Adam text editor and going

147
00:08:13,550 --> 00:08:15,620
through a couple of more examples.

148
00:08:15,620 --> 00:08:17,820
Ok here I am again at my example that PI.

149
00:08:17,870 --> 00:08:23,880
I'm going to delete this print statement save that change and when to clear out my terminal here.

150
00:08:24,290 --> 00:08:26,800
OK so the first thing going to do is just do an assignment.

151
00:08:26,810 --> 00:08:32,770
So say a is equal to the number 10 and then I can print out a.

152
00:08:32,800 --> 00:08:34,820
Let's save that.

153
00:08:35,000 --> 00:08:38,090
And when I run this I get back 10.

154
00:08:38,160 --> 00:08:39,340
So now I have high.

155
00:08:39,390 --> 00:08:42,590
I've assigned the variable a to the number 10.

156
00:08:42,630 --> 00:08:45,590
Now it's really interesting as I can actually use a to read the fine.

157
00:08:45,900 --> 00:08:52,050
So then later on in my code what I could say is OK now am going to be equal to a plus a.

158
00:08:52,140 --> 00:08:53,310
So what does that actually mean.

159
00:08:53,310 --> 00:08:57,850
It means a starts off as 10 and then you're going to reassign it to be equal to a plus a.

160
00:08:57,900 --> 00:09:03,480
So then you would expect when you print out a after that to get 20 because 10 plus 10 is 20 which is

161
00:09:03,480 --> 00:09:05,090
what happened exactly when and run it.

162
00:09:05,100 --> 00:09:07,370
Now you get back 20 as the output.

163
00:09:07,800 --> 00:09:11,820
OK let's show you a more realistic example because you won't just be using variable names like this.

164
00:09:11,820 --> 00:09:16,720
Let's imagine that we just had a bunch of puppies born so let's say six puppies were born.

165
00:09:17,500 --> 00:09:19,270
So we'll say puppies is equal to six.

166
00:09:19,340 --> 00:09:24,260
And each of them weighs two pounds which I'm actually not sure if that's a lot or a little for a puppy

167
00:09:24,290 --> 00:09:26,500
but hopefully bear with me here.

168
00:09:26,720 --> 00:09:28,370
So two pounds per puppy.

169
00:09:28,370 --> 00:09:31,300
Now the question is what's the total weight of all the puppies.

170
00:09:31,520 --> 00:09:36,000
Well now I can use variable names to easily find this in a very readable way.

171
00:09:36,080 --> 00:09:45,040
I'll just say something like total Ezekial to puppies times and then I'll just print out the totals

172
00:09:45,260 --> 00:09:47,670
to report that.

173
00:09:47,730 --> 00:09:48,750
So say that again.

174
00:09:48,750 --> 00:09:52,710
All I'm doing here is variable assignments and then I'm working the variables of the same arithmetic

175
00:09:52,770 --> 00:09:55,190
I was working with numbers when I run this.

176
00:09:55,230 --> 00:09:58,510
Now I get back the result six times two which is 12.

177
00:09:58,530 --> 00:10:00,610
So now my total is assigned to 12.

178
00:10:00,630 --> 00:10:01,160
OK.

179
00:10:01,290 --> 00:10:06,030
So we just learned some of the basics of numbers and arithmetic and also how we can create what are

180
00:10:06,030 --> 00:10:10,490
essentially labels for all these data types through the use of variable assignments.

181
00:10:10,500 --> 00:10:14,430
Hopefully this was pretty intuitive and pretty straightforward but if you have any questions feel free

182
00:10:14,430 --> 00:10:15,990
to post the Q&amp;A forums.

183
00:10:15,990 --> 00:10:17,010
We'll see you at the next lecture.
