Instructor: Welcome back.
So, up until now, we've learned about integers,
floats, strings and Boolean values.
So let's try and tie some of those things together.
Let's imagine your Facebook.
How do you think Facebook works
underneath the hood when it comes to your profile?
Well, they would have, let's say, a variable
called name and this will have your name
and then they'll probably have a variable with your age.
Let's say 50.
I'm not actually 50, but I'm pretending to be
for this case just so I sound wiser.
And then let's say relationship status.
So again, we also have relationship status on Facebook
and for now, let's say single.
So that's my Facebook profile right there.
Now, if we wanted to perhaps change that,
let's say my relationship status all of a sudden goes
from single to it's complicated,
well, that's an easy fix.
We would just do relationship status equals two.
It's complicated.
And remember, because of the single quote,
we'll have to do back slash
it's complicated.
And now if I print my relationship status,
you'll see that it's been updated to it's complicated.
I am no longer single, hooray.
But this is pretty simple.
Let's do something more complicated,
and this is going to be a fun exercise.
Let's create a program
that guesses your age.
Let's use the input method
that we've seen before.
Remember, the input method allows us to type something
in here and receive it as input,
so we can assign that to a variable.
So, let's say this variable is going to be birth year.
And that's going to equal the input.
That's going to ask when or what year
were you born.
Now from here, I want you to pause the video
and try to solve this yourself.
How can you make it, so that at the end of this program,
you're going to get asked what year were you born?
You're going to type in your year
and then it's going to print out
your age is, whatever the age is.
So pause the video, try and solve this on your own.
Mind you, there is a bit of a trick in here,
so if you get stuck, try to Google around
and figure out what the issue may be.
Again, part of being a programmer is trying
to solve these problems that you don't know the answers to.
All right, let me show you my solution.
We have our birth year here
that we're going to store in a variable.
And now, we're going to calculate the age.
I'm going to say age equals,
well, it's going to equal the current year, let's say 2019.
And then 2019 here is going to get subtracted
from whatever the birth year that you entered.
So let's enter that,
and then we're simply going to say print your age is,
and we want to use an F string here.
So I'm going to add an F here,
and then simply say age.
If I run this, I get,
what year were you born?
I was born in 1986.
Hmm, we get an error, and if you try this yourself
you may have encountered this error.
We get something called a type error,
and there's lots of errors that you can get in Python.
Again, we have a section on error, so don't stress too much
about it, but if you read here it says
unsupported operand type S
for minus int and string.
Hmm, let's try and debug this.
It looks like we're using minus
on an integer and a string.
So let me print out here
the type of birth year.
If I run this, and let's enter 1986.
I get class string, and this is a little gotcha
because what input does
is it asks you for an input,
but that input that I wrote, 1986,
well, that actually gets converted to a string
and assigned to birth year.
So what that means is that we're trying to subtract
a number or a string from a number.
So how do we solve this issue?
Well, you'd have to turn this into an integer
and this is something that we saw previously.
What we need to do is to convert this
into an integer with using the int function.
So let's try that.
If I remove this and click run,
I'll say 1986, and look at that.
Your age is 33.
We've created a program that was able to tell your age
based on the year that you were born.
Now, this may have been tricky to you
but it teaches an important concept in programming.
That is sometimes you're storing data
into different data types, and sometimes
you need those different data types to interact together.
So you'll see a lot of problems where you have
to convert a data type, and this is a very
common one where you take an input that's a string
and then you convert it to something like an integer.
So you can perform a mathematical operation.
And that's why, if you remember, we gave you a list
of all our data types in Python, the fundamental data types
and all of them were blue because, well,
each one of these are actions, are functions
that we can use.
For example, I converted the birth year
into integer but I could have also converted this
to a float, for example.
And if I run this, it would still work
because Python knows that,
well, we can use integers
and floats in mathematical operation,
but you can see here that it's converted into a float now.
If we convert this into a Boolean and I click run.
Your age is 2018.
That's really confusing, right?
Well, that's because this gets turned
into true and underneath the hood,
Python does something weird where
a true value is converted to one.
Because Boolean, remember, it's one or zero.
True or false.
All right, hopefully this didn't confuse you too much.
It's something that we'll encounter throughout the course
so don't worry, we'll get more and more practice.
However, I hope you get to practice this a little bit
to really understand what's going on
because although this is a couple of lines of code,
the principles that we use here,
we're going to use throughout bigger and bigger code bases.
So I guess I'll see you in the next one.
Bye-bye.