Welcome everyone to this lecture on variables and not PI files.
So in this lecture, we're going to cover the very basics of running a Dart Pi or Python extension file,
then we'll talk about printing results out so you can actually see results in your command line.
Then we'll talk about just basic arithmetic with Python.
What are the symbols you should know, as well as variable assignment how that works of Python?
OK, let's get started.
I'm going to go and open up visual studio code.
OK, here I am in a Visual Studio code.
Now, if you skip all the way to this section of the course, please make sure you watch the installation
and setup for Visual Studio code, or you talk about setting up and installing Python with Visual Studio
code, as well as setting up your terminal.
What we're going to do right now is just set up a terminal instance inside Visual Studio code so we
can actually run a Python file.
So I'm going to hit Terminal here and I can open up a new terminal.
You should notice that if you're on a Windows computer, this will by default open up Windows PowerShell.
Sometimes this actually has issues of Python, depending how you install it.
These days, it should normally work, but just in case what I'm going to do is, I'm actually going
to open up my command prompt if you're only Mac OS or Linux.
This should pretty much open what's known as your Mac OS or Linux Terminal, and you should be OK.
You don't need to actually do this step.
This is just for Windows users.
You click over here on this little power down, not the plus sign, but the dropdown and then hit command
prompt.
And it's now going to open up command prompt or seemed.
And a Mexican then put the little trashcan here to delete the PowerShell.
OK.
So I have my command prompt opened up.
And then notice it's opened up at the same location where I've been on my desktop underneath Django
lectures.
So what I'm going to do is at Django Lectures, I will create a new file and I will call this example.
But now it's going to have the extension dot pi and notice.
Now Visual Studio code is smart enough to understand, OK, this is a Python file because it has Dot
Pi and I'm going to collapse the explorer here and let me show you how to run Python at your terminal,
as well as run a Python script at your terminal.
So Python does have the ability to be run at the command line.
And if you were just to type in Python like this and then hit Enter, once you have Python installed,
you're going to see this output here, which allows you to run Python commands, so you'd actually be
able to do something like one plus one hit enter and see the result of two.
Now, typically, we're not actually going to be using the terminal because I would have to enter all
my code line by line by line.
I'd rather have it all in a nice script and then just run the entire script.
So if you want to quit out of this?
You can say quit open, close parentheses there, enter and notice I'm no longer running Python.
So if you ever see yourself having some output like this where it says the version of Python when you
installed it and then something like tape help copyright and you meant to actually run a file, go ahead
and run quit first.
And if you're on windows, you want to clear the screen.
You can type seals if you're on Mac OS or Linux, it's just clear.
So seals here to clear that.
OK, so let's go ahead and explore how to actually run Python code within our PI file.
So how can I do this?
What I'm going to do is I'm pretty zoomed in here, but I was going to type in one.
Plus one.
I'm going to save that change, and I'm going to show you kind of a common and beginner mistake before
actually should have fixed this.
So a lot of times beginners have some sort of logic here, like one plus one and they want to run this
Python script.
So what they say is they come here and then they say Python space and then example that pie.
This is actually how you run the Python script.
This is saying using Python, execute this that file.
Notice this That pie file is currently located at this location underneath desktop jingle lectures.
If I were to just enter right now, it would run the file, but I wouldn't see the output.
A lot of times students expect, Hey, where's the two?
Well, the reason you're not seeing anything is because with Python, you have to be explicit about
what you want to show as output.
And in that case, you're going to need to say print.
Open close parentheses, one plus one.
Go ahead and save that change, remember to save it, there's a little circle here.
Another really common mistake by beginners is they kind of forget to save their changes here and then
run that code again.
A shortcut for running the same code.
If you go up Arrow, you get to see the history of commands put to the terminal so you can keep doing
up errors or down errors.
So I'm going to run Python.
Example that pi again.
I hit there and now I actually see the result, too.
So I see two because I said print one plus one.
So now that we understand how to run a python file, let's go ahead and run through some arithmetic.
The last thing I want to show you is a real quick example of a common mistake.
I see beginners do all the time.
A lot of times they accidentally do this.
They type Python enter, and now they're actually running Python.
And then they try to do something like this python example that python.
They hit enter and then they get this syntax error.
That's because Python thinks you're actually trying to run Python code instead of using Python to execute
that that file.
So just be careful of this.
I see a lot of beginners using Python X to make this mistake.
So just keep that in mind if you ever see something like this because you accidentally are running the
Python interpreter at the command line instead of executing the actual that file.
So now I'm going to.
Quit this, OK?
And let's clear that out.
Oops, see less.
There we go.
OK, so I can't add numbers by just saying something like one plus one.
And if I say Python, example that pi, I can keep executing to see the results here if I want to multiply.
Then that's going to be an Asterix site so I can say 20 Asterix times.
20 save that change.
And now this should be 400.
So you see the result there.
Other commands you may want to know is a minus for subtraction.
So basically, what you would expect, it's going to be zero there.
If you have something like exponential powers, that's going to be two Asterix signs.
It's not a carrot symbol.
So if you want to to the power of three, it's going to be two asterisks and then two, the power three
there saved that change.
And then you can go ahead and run it here and you see it's eight.
OK.
And then keep in mind, order of operations are followed.
So you can have some sort of formula here inside the print statement so you can use parentheses for
that.
Hopefully not too confusing using so many ways, but you can do something like do two percent first
and then multiply it by the result of, let's say, 10 plus three.
This is just to give you a little bit of lingo into logic.
And then if you run into that, you can say it's 156, essentially saying it's going to execute 12 times
13.
So order of operations there?
OK.
So it's going to get a little annoying to have to keep writing all these numbers.
Typically, what you want to do is actually use variable assignments.
So instead of saying two plus 10 or 10 plus three, usually these four numbers are referring to Real-World
things.
So to do a variable assignment, you use a single equals sign.
So how do we do that kind of cleared my terminal here, span this and then inside example that PI,
I'm going to create a very simple idea.
Let's imagine I have my income and my income is $100, and I want to figure out what I pay in taxes.
And let's say my tax rate is going to be equal to 10 percent or zero point one for variable assignment
with Python.
The variables are going to follow what's known as snake casing, where every single kind of separate
word here is split up with an underscore.
And then you choose your variable name.
Notice how when I hover over it at Visual Studio Code actually tells me, Hey, this is a variable and
it's equal to 100, so that's perfect.
Then what I can do is say tax rate.
That's a new variable on a new line.
And then that's going to be equal to zero point one.
Then I'm going to enter here and I'm going to actually assign a new variable for my own taxes.
So this is what taxes I would owe and that would simply be equal to my income.
And notice visual studio code actually starts kind of auto completing and helping you hear something
to say.
My income multiplied.
That's an asterisk.
Times.
My tax rate.
OK, so again, what's happening here is I'm using variables now to actually run this and then I have
my taxes is equal to my income times tax rate, so I have a little pop quiz for you.
If I were to save these changes.
And run python example that pie.
What would I see as the output?
Now, if you said you would see 10, you're actually incorrect.
Remember, I need to print something if I want to see the output.
If I just run python, example that pie, I get no output.
Common beginner mistake.
Well, we need to do is come here and say print.
My taxes saved that change and then run this, and you can see now I have 10 here.
And if you're wondering why it says ten point zero instead of just 10, that's because there's a difference
here between my income and tax rate as far as arithmetic or no type.
This is what's known as an integer, just a whole number.
And this is known as a floating point number, which means it has specificity past the actual decimal
point.
And when you begin to do arithmetic operations between an integer and a floating point number, it's
just going to have the result be a floating point number like ten point zero instead of ten.
This is going to show you that extra information for pretty much all our use cases.
We don't really care about this, whether it's 10 or ten point zero, and we don't really care too much
about the difference between integers and floating point numbers.
We just care that the mathematics makes sense here.
So that's the very basics of running a python file.
Setting up variables and also the very basics of arithmetic and printing your output.
And that's pretty much all we need to know so far.
Coming up next, we're going to do is have a discussion on strings and different properties about strings.
I'll see you there.