1
00:00:05,220 --> 00:00:08,850
Welcome everyone to this lecture on variables and not PI files.

2
00:00:10,020 --> 00:00:15,090
So in this lecture, we're going to cover the very basics of running a Dart Pi or Python extension file,

3
00:00:15,480 --> 00:00:19,590
then we'll talk about printing results out so you can actually see results in your command line.

4
00:00:19,920 --> 00:00:22,430
Then we'll talk about just basic arithmetic with Python.

5
00:00:22,440 --> 00:00:26,370
What are the symbols you should know, as well as variable assignment how that works of Python?

6
00:00:26,790 --> 00:00:27,870
OK, let's get started.

7
00:00:28,140 --> 00:00:30,630
I'm going to go and open up visual studio code.

8
00:00:31,110 --> 00:00:33,450
OK, here I am in a Visual Studio code.

9
00:00:33,840 --> 00:00:39,000
Now, if you skip all the way to this section of the course, please make sure you watch the installation

10
00:00:39,000 --> 00:00:44,160
and setup for Visual Studio code, or you talk about setting up and installing Python with Visual Studio

11
00:00:44,160 --> 00:00:45,750
code, as well as setting up your terminal.

12
00:00:46,260 --> 00:00:51,360
What we're going to do right now is just set up a terminal instance inside Visual Studio code so we

13
00:00:51,360 --> 00:00:53,400
can actually run a Python file.

14
00:00:53,820 --> 00:00:57,660
So I'm going to hit Terminal here and I can open up a new terminal.

15
00:00:58,170 --> 00:01:03,540
You should notice that if you're on a Windows computer, this will by default open up Windows PowerShell.

16
00:01:03,840 --> 00:01:07,230
Sometimes this actually has issues of Python, depending how you install it.

17
00:01:07,500 --> 00:01:11,880
These days, it should normally work, but just in case what I'm going to do is, I'm actually going

18
00:01:11,880 --> 00:01:15,510
to open up my command prompt if you're only Mac OS or Linux.

19
00:01:15,780 --> 00:01:20,180
This should pretty much open what's known as your Mac OS or Linux Terminal, and you should be OK.

20
00:01:20,190 --> 00:01:21,390
You don't need to actually do this step.

21
00:01:21,420 --> 00:01:22,590
This is just for Windows users.

22
00:01:22,920 --> 00:01:28,740
You click over here on this little power down, not the plus sign, but the dropdown and then hit command

23
00:01:28,740 --> 00:01:29,160
prompt.

24
00:01:29,550 --> 00:01:32,250
And it's now going to open up command prompt or seemed.

25
00:01:32,700 --> 00:01:35,820
And a Mexican then put the little trashcan here to delete the PowerShell.

26
00:01:36,180 --> 00:01:36,480
OK.

27
00:01:36,870 --> 00:01:39,840
So I have my command prompt opened up.

28
00:01:40,290 --> 00:01:45,900
And then notice it's opened up at the same location where I've been on my desktop underneath Django

29
00:01:45,900 --> 00:01:46,470
lectures.

30
00:01:47,400 --> 00:01:54,150
So what I'm going to do is at Django Lectures, I will create a new file and I will call this example.

31
00:01:54,660 --> 00:01:58,290
But now it's going to have the extension dot pi and notice.

32
00:01:58,290 --> 00:02:03,600
Now Visual Studio code is smart enough to understand, OK, this is a Python file because it has Dot

33
00:02:03,600 --> 00:02:09,090
Pi and I'm going to collapse the explorer here and let me show you how to run Python at your terminal,

34
00:02:09,360 --> 00:02:12,810
as well as run a Python script at your terminal.

35
00:02:13,260 --> 00:02:16,230
So Python does have the ability to be run at the command line.

36
00:02:16,350 --> 00:02:22,290
And if you were just to type in Python like this and then hit Enter, once you have Python installed,

37
00:02:22,560 --> 00:02:27,960
you're going to see this output here, which allows you to run Python commands, so you'd actually be

38
00:02:27,960 --> 00:02:33,750
able to do something like one plus one hit enter and see the result of two.

39
00:02:34,170 --> 00:02:38,100
Now, typically, we're not actually going to be using the terminal because I would have to enter all

40
00:02:38,100 --> 00:02:39,750
my code line by line by line.

41
00:02:40,110 --> 00:02:43,380
I'd rather have it all in a nice script and then just run the entire script.

42
00:02:43,770 --> 00:02:45,690
So if you want to quit out of this?

43
00:02:47,100 --> 00:02:52,300
You can say quit open, close parentheses there, enter and notice I'm no longer running Python.

44
00:02:52,320 --> 00:02:57,240
So if you ever see yourself having some output like this where it says the version of Python when you

45
00:02:57,240 --> 00:03:02,280
installed it and then something like tape help copyright and you meant to actually run a file, go ahead

46
00:03:02,280 --> 00:03:03,510
and run quit first.

47
00:03:04,380 --> 00:03:06,300
And if you're on windows, you want to clear the screen.

48
00:03:06,630 --> 00:03:09,750
You can type seals if you're on Mac OS or Linux, it's just clear.

49
00:03:10,170 --> 00:03:12,030
So seals here to clear that.

50
00:03:12,360 --> 00:03:18,730
OK, so let's go ahead and explore how to actually run Python code within our PI file.

51
00:03:19,440 --> 00:03:20,990
So how can I do this?

52
00:03:21,000 --> 00:03:25,290
What I'm going to do is I'm pretty zoomed in here, but I was going to type in one.

53
00:03:26,610 --> 00:03:27,210
Plus one.

54
00:03:28,780 --> 00:03:32,710
I'm going to save that change, and I'm going to show you kind of a common and beginner mistake before

55
00:03:32,720 --> 00:03:33,770
actually should have fixed this.

56
00:03:34,120 --> 00:03:38,890
So a lot of times beginners have some sort of logic here, like one plus one and they want to run this

57
00:03:38,890 --> 00:03:39,680
Python script.

58
00:03:39,700 --> 00:03:46,210
So what they say is they come here and then they say Python space and then example that pie.

59
00:03:46,300 --> 00:03:48,190
This is actually how you run the Python script.

60
00:03:48,220 --> 00:03:52,480
This is saying using Python, execute this that file.

61
00:03:52,780 --> 00:03:58,900
Notice this That pie file is currently located at this location underneath desktop jingle lectures.

62
00:03:59,290 --> 00:04:04,150
If I were to just enter right now, it would run the file, but I wouldn't see the output.

63
00:04:04,180 --> 00:04:07,030
A lot of times students expect, Hey, where's the two?

64
00:04:07,450 --> 00:04:12,190
Well, the reason you're not seeing anything is because with Python, you have to be explicit about

65
00:04:12,190 --> 00:04:14,230
what you want to show as output.

66
00:04:14,590 --> 00:04:16,959
And in that case, you're going to need to say print.

67
00:04:18,110 --> 00:04:20,510
Open close parentheses, one plus one.

68
00:04:21,019 --> 00:04:23,870
Go ahead and save that change, remember to save it, there's a little circle here.

69
00:04:24,080 --> 00:04:28,400
Another really common mistake by beginners is they kind of forget to save their changes here and then

70
00:04:28,400 --> 00:04:29,480
run that code again.

71
00:04:29,600 --> 00:04:30,980
A shortcut for running the same code.

72
00:04:30,980 --> 00:04:35,410
If you go up Arrow, you get to see the history of commands put to the terminal so you can keep doing

73
00:04:35,420 --> 00:04:36,770
up errors or down errors.

74
00:04:37,340 --> 00:04:38,390
So I'm going to run Python.

75
00:04:38,390 --> 00:04:39,440
Example that pi again.

76
00:04:40,040 --> 00:04:42,910
I hit there and now I actually see the result, too.

77
00:04:43,670 --> 00:04:46,820
So I see two because I said print one plus one.

78
00:04:47,150 --> 00:04:52,850
So now that we understand how to run a python file, let's go ahead and run through some arithmetic.

79
00:04:52,910 --> 00:04:56,570
The last thing I want to show you is a real quick example of a common mistake.

80
00:04:56,570 --> 00:04:57,920
I see beginners do all the time.

81
00:04:58,190 --> 00:04:59,930
A lot of times they accidentally do this.

82
00:04:59,990 --> 00:05:03,780
They type Python enter, and now they're actually running Python.

83
00:05:03,800 --> 00:05:07,190
And then they try to do something like this python example that python.

84
00:05:07,190 --> 00:05:09,320
They hit enter and then they get this syntax error.

85
00:05:09,560 --> 00:05:14,840
That's because Python thinks you're actually trying to run Python code instead of using Python to execute

86
00:05:14,840 --> 00:05:15,710
that that file.

87
00:05:15,950 --> 00:05:16,930
So just be careful of this.

88
00:05:16,940 --> 00:05:19,820
I see a lot of beginners using Python X to make this mistake.

89
00:05:20,120 --> 00:05:24,200
So just keep that in mind if you ever see something like this because you accidentally are running the

90
00:05:24,200 --> 00:05:28,310
Python interpreter at the command line instead of executing the actual that file.

91
00:05:28,520 --> 00:05:29,630
So now I'm going to.

92
00:05:30,610 --> 00:05:31,900
Quit this, OK?

93
00:05:31,930 --> 00:05:33,100
And let's clear that out.

94
00:05:34,180 --> 00:05:35,440
Oops, see less.

95
00:05:36,190 --> 00:05:36,640
There we go.

96
00:05:37,180 --> 00:05:41,530
OK, so I can't add numbers by just saying something like one plus one.

97
00:05:42,070 --> 00:05:48,880
And if I say Python, example that pi, I can keep executing to see the results here if I want to multiply.

98
00:05:49,180 --> 00:05:53,800
Then that's going to be an Asterix site so I can say 20 Asterix times.

99
00:05:53,800 --> 00:05:55,760
20 save that change.

100
00:05:55,780 --> 00:05:57,450
And now this should be 400.

101
00:05:57,460 --> 00:05:58,500
So you see the result there.

102
00:05:59,080 --> 00:06:02,290
Other commands you may want to know is a minus for subtraction.

103
00:06:02,330 --> 00:06:05,800
So basically, what you would expect, it's going to be zero there.

104
00:06:06,280 --> 00:06:11,000
If you have something like exponential powers, that's going to be two Asterix signs.

105
00:06:11,020 --> 00:06:12,370
It's not a carrot symbol.

106
00:06:12,790 --> 00:06:19,450
So if you want to to the power of three, it's going to be two asterisks and then two, the power three

107
00:06:19,450 --> 00:06:21,310
there saved that change.

108
00:06:22,420 --> 00:06:25,420
And then you can go ahead and run it here and you see it's eight.

109
00:06:25,780 --> 00:06:26,140
OK.

110
00:06:26,650 --> 00:06:29,410
And then keep in mind, order of operations are followed.

111
00:06:29,680 --> 00:06:34,000
So you can have some sort of formula here inside the print statement so you can use parentheses for

112
00:06:34,000 --> 00:06:34,240
that.

113
00:06:35,470 --> 00:06:39,820
Hopefully not too confusing using so many ways, but you can do something like do two percent first

114
00:06:40,240 --> 00:06:45,250
and then multiply it by the result of, let's say, 10 plus three.

115
00:06:45,280 --> 00:06:48,160
This is just to give you a little bit of lingo into logic.

116
00:06:48,610 --> 00:06:55,000
And then if you run into that, you can say it's 156, essentially saying it's going to execute 12 times

117
00:06:55,000 --> 00:06:55,640
13.

118
00:06:55,660 --> 00:06:57,400
So order of operations there?

119
00:06:57,820 --> 00:06:58,180
OK.

120
00:06:58,750 --> 00:07:02,270
So it's going to get a little annoying to have to keep writing all these numbers.

121
00:07:02,350 --> 00:07:05,770
Typically, what you want to do is actually use variable assignments.

122
00:07:05,890 --> 00:07:12,070
So instead of saying two plus 10 or 10 plus three, usually these four numbers are referring to Real-World

123
00:07:12,070 --> 00:07:12,550
things.

124
00:07:12,730 --> 00:07:16,870
So to do a variable assignment, you use a single equals sign.

125
00:07:17,260 --> 00:07:24,190
So how do we do that kind of cleared my terminal here, span this and then inside example that PI,

126
00:07:24,550 --> 00:07:27,430
I'm going to create a very simple idea.

127
00:07:27,430 --> 00:07:35,800
Let's imagine I have my income and my income is $100, and I want to figure out what I pay in taxes.

128
00:07:36,010 --> 00:07:41,560
And let's say my tax rate is going to be equal to 10 percent or zero point one for variable assignment

129
00:07:41,560 --> 00:07:42,220
with Python.

130
00:07:42,520 --> 00:07:47,740
The variables are going to follow what's known as snake casing, where every single kind of separate

131
00:07:47,740 --> 00:07:49,960
word here is split up with an underscore.

132
00:07:50,290 --> 00:07:52,210
And then you choose your variable name.

133
00:07:52,270 --> 00:07:57,730
Notice how when I hover over it at Visual Studio Code actually tells me, Hey, this is a variable and

134
00:07:57,730 --> 00:08:00,160
it's equal to 100, so that's perfect.

135
00:08:00,670 --> 00:08:02,500
Then what I can do is say tax rate.

136
00:08:04,000 --> 00:08:06,040
That's a new variable on a new line.

137
00:08:06,580 --> 00:08:08,410
And then that's going to be equal to zero point one.

138
00:08:09,660 --> 00:08:15,660
Then I'm going to enter here and I'm going to actually assign a new variable for my own taxes.

139
00:08:15,900 --> 00:08:20,230
So this is what taxes I would owe and that would simply be equal to my income.

140
00:08:20,250 --> 00:08:24,590
And notice visual studio code actually starts kind of auto completing and helping you hear something

141
00:08:24,600 --> 00:08:24,840
to say.

142
00:08:24,840 --> 00:08:26,670
My income multiplied.

143
00:08:26,670 --> 00:08:27,510
That's an asterisk.

144
00:08:27,810 --> 00:08:28,320
Times.

145
00:08:29,890 --> 00:08:30,460
My tax rate.

146
00:08:31,240 --> 00:08:37,960
OK, so again, what's happening here is I'm using variables now to actually run this and then I have

147
00:08:37,960 --> 00:08:43,659
my taxes is equal to my income times tax rate, so I have a little pop quiz for you.

148
00:08:44,140 --> 00:08:46,330
If I were to save these changes.

149
00:08:47,600 --> 00:08:49,520
And run python example that pie.

150
00:08:49,790 --> 00:08:51,230
What would I see as the output?

151
00:08:52,190 --> 00:08:56,240
Now, if you said you would see 10, you're actually incorrect.

152
00:08:56,510 --> 00:08:59,720
Remember, I need to print something if I want to see the output.

153
00:08:59,870 --> 00:09:03,080
If I just run python, example that pie, I get no output.

154
00:09:03,240 --> 00:09:04,340
Common beginner mistake.

155
00:09:04,730 --> 00:09:07,070
Well, we need to do is come here and say print.

156
00:09:09,740 --> 00:09:16,640
My taxes saved that change and then run this, and you can see now I have 10 here.

157
00:09:17,030 --> 00:09:21,800
And if you're wondering why it says ten point zero instead of just 10, that's because there's a difference

158
00:09:21,800 --> 00:09:26,330
here between my income and tax rate as far as arithmetic or no type.

159
00:09:26,660 --> 00:09:29,150
This is what's known as an integer, just a whole number.

160
00:09:29,450 --> 00:09:35,270
And this is known as a floating point number, which means it has specificity past the actual decimal

161
00:09:35,270 --> 00:09:35,660
point.

162
00:09:35,930 --> 00:09:41,570
And when you begin to do arithmetic operations between an integer and a floating point number, it's

163
00:09:41,570 --> 00:09:45,980
just going to have the result be a floating point number like ten point zero instead of ten.

164
00:09:46,010 --> 00:09:49,580
This is going to show you that extra information for pretty much all our use cases.

165
00:09:49,580 --> 00:09:53,660
We don't really care about this, whether it's 10 or ten point zero, and we don't really care too much

166
00:09:53,660 --> 00:09:56,060
about the difference between integers and floating point numbers.

167
00:09:56,300 --> 00:09:58,490
We just care that the mathematics makes sense here.

168
00:09:58,670 --> 00:10:02,060
So that's the very basics of running a python file.

169
00:10:02,330 --> 00:10:07,460
Setting up variables and also the very basics of arithmetic and printing your output.

170
00:10:07,790 --> 00:10:09,980
And that's pretty much all we need to know so far.

171
00:10:10,310 --> 00:10:15,410
Coming up next, we're going to do is have a discussion on strings and different properties about strings.

172
00:10:15,740 --> 00:10:16,340
I'll see you there.

