>> So I've got Visual Studio open.
Let's go and take a look at some code.
So I'm going to create my variable pi
14159 I know of is more digits and app but I've gotta stop
somewhere and I'm storing that value in a variable and then I
can just print that value up on
the screen using control S to save here.
I love using keyboard shortcuts
and why just trying to get that message go away. There we go.
Now that I'm here, run my code and you will see that it displays.
There's my number 3.14159 on the screen.
So again, just showing
yes of course I can store numbers and variables as well.
Of course, once I'm storing numbers and variables,
let me just comment out this code.
Control case C. By the way
the keyboard shortcut for commenting out code,
and now I can store a couple of numbers,
first number equals five,
second number equals six,
and then I can add those numbers together so I can do
a print statement of first number plus second number.
Because of course the main reason we want to
store numbers is because we're going to need to do math with them.
So now I go ahead and I run this code using the up arrow.
Recall my last command and it comes back and returns 11.
You can change that to a multiply and then you see 30.
I can change that to
a double exponent which means to the power of,
save that code rerun,
and apparently five to the power of six is 15,625.
I admit that's beyond
the capabilities of what I can do in my head.
But that's why I like computers,
they'll figure that stuff out for me. Computers are good at math.
So this is a fairly common situation.
But as I mentioned, one of
the problems you will run into is let's say I
start asking the user to
enter the values for the first and second number.
So I say, "Hey,
do an input statement and ask for user,
please enter a number and I'm
going to take the number they entered and store it in
that variable first_num and then,
I say please enter
another number and I
decide to store that in the variable second_num.
So all I've done is taking
the value for first number and
second number and taking it from the input statement.
The rest of my code is the same and yet,
now when I run, it changes
to a actually this you'd probably give me near it,
will try this, and it goes enter number
I enter five and number six and it goes on,
"Unsupported operand type for"
the asterisk outer skirt score the power command.
It's like it's got a string and a string.
Well, what susan to the power of i back.
So the problem is it has two strings.
I can demonstrate this by changing to the power of symbols to
a plus sign because now you'll
see the two strings concatenated together.
So now if I run and I'll just move this to top the screen.
So you can see it better and I enter a number
five and the number six and you see it come back with 56.
So this is the problem I was talking about where
the numbers are being treated as strings,
because the input function always returns a string
even if that string contains a number a little confusing I know.
So let's go in and fix that.
So what we have to do,
is we have to go in here and say treat this number as
an integer and treat
this number as an integer or take
this variable and convert it to an integer.
Now, when we enter five and six,
you can see it actually correctly does a math and returns 11.
If you and we change that to a float rather than an integer,
the only difference is an integer is for whole numbers,
a float can contain decimal numbers.
So the only difference is going to be that
when I entered the numbers, it shows 11.0.
Just a way of me recognizing.
It's a number of it can contain decimals a floating point number.
So here I've used datatype conversion to
take a number of stored in a string to treat it as a number.
But there was one other scenario
where we had to do datatype conversion as well.
So let's take a look at that one.
So I'm going to comment out this code, control K C,
to do that and what I'm going
to do is I'm going to say days in February,
help if I could type, February
if I could spell it like it spell February as well
apparently equals 28 and then I say print days in February,
there we go, plus and I want to concatenate
that total days in February.
So sometimes we want to display a number
inside a string on the screen.
So now when I go and I run this,
go down here just clear the screen again with the CLS,
and we see it again it blows up.
Take a look at that error message says unsupported operand type.
You have a plus sign is the operand and you're trying
to give it an integer and a string.
So it's confused. Python doesn't
know is this two numbers I should add
up with math or two strings I should concatenate together,
because it has one number and one string.
So we have to use the string function
to convert days in February into a string datatype.
So now, when I go and run it,
it comes back perfectly happily and
comes back and says 28 total days in February.
So now you have you build you use numbers in your code but
do be prepared to start doing
battle with some data type conversions string,
int, and float could become your new best friends.