Are you ready to go deeper and Python?
I hope you are because this is episode two of my free Python course,
where I'm going to teach you everything you need to know to become dangerous
in Python.
So here we go, armed with coffee and the knowledge from episode one,
where we talked about strings and things.
We're now moving on to talk about one of the most fundamental things in Python
and really just programming in general variables. The variables are fun.
I can't wait to show you now. What do you need to learn this? Well,
just like episode one, nothing.
I have a free Python lab available in the description. Seriously.
It's amazing right here from your browser,
you can program in Python or even from your phone. It's awesome. Oh,
and almost forgot you need coffee. It's just required. I didn't make the rules.
And also a massive shout out to the sponsor of this entire series and why it can
be free here on YouTube. It pro TV.
I use it pro TV to learn pretty much everything in it.
From networking to hacking.
If you want to get your CCNA or A-plus or Linux plus,
or pretty much whatever that got you back with amazing top notch,
video training and hands-on labs and Python did. I mentioned Python.
They had these amazing Python courses that cover some fun stuff like Python for
security and Python for networking professionals. That's just cool. So anyways,
you want, wanna check them out?
You definitely should use my link below where code network Chuck,
and get 30% off forever. Now I need your help with something you and me.
We're going to start a coffee shop together. Yes.
It's going to be called the network. chuck.coffee, coffee shop.
We'll work on the name and to do that, we're going to be a bit geeky about it.
We're going to program our own baristas. So here in this video,
we're going to write some code to automate our baristas. How cool was that?
Anyway, let's do this. So go ahead and launch your lab. Check that link.
And the description again is going to be right here in your browser.
And it's so cool. First quick review.
What the junk is that judging by the hashtag in front of it?
Hashtag that's comment, right? Telling us it's for us and not the computer.
So yeah, we're starting a coffee shop together.
Let's add one more comment to talk about what we're about to do.
Put a hashtag in. Let's build a robot barista. Now again, quick review.
When we click run to run this code, what's going to show up right here. Try it.
Nothing because the computer ignored all this stuff. Let's give us some stuff.
It can't ignore. Let's do this now first with any great barista.
We want them to say a greeting. When someone comes in, hello,
welcome to network chuck.coffee. So let's make our computer barista say that.
How would you do that? Well, simple right? To make our computer talk.
We print print using a print function parentheses.
And then between those parentheses, we'll add what it should say,
which will be a string. So we'll say hello,
welcome to network Chuck coffee. And they've had a lot of coffee today.
So at a bunch of exclamation points, yes. A robot runs on coffee.
You didn't know that. And that's it. And again,
quick review print right here is our function. It's got the parentheses.
And then in between those parentheses,
we have our string because it's between quotes, which by the way,
did you say string like this all day from the last episode,
if you did let me know in the discussion or the comments and when we print this,
what do you think is going to show up right here? Let's see. Is it programming?
Fun? This so fun. Let's hit run. Cool. We made the computer talk.
So our robot barista, he's already well-trained.
He knows how to say hi to people, but he needs to be more than that, right?
If you want us to actually make coffee. Now,
if you've ever been to a coffee shop, you know,
any good barista is going to ask you what your name is so they can write that
sucker on the cup. Right? So here we go.
Let's make our robot barista ask you what your name is. Prince string.
What is your name? So we get to print functions, two strings.
And if we click run on that sucker run, cool. What's your name?
So we made our robot barista talk,
but how do we make it to where we can talk back to our robot barista?
And he hears us. He takes the information in that's our next cool thing.
We're going to learn. So check this out.
It's something called the input function, who? Yes.
If I go in and type it in with me right now,
just type in the word input and then parentheses open and close.
Yes, sir.
This one's super cool and opens up the door for us to have a lot of fun.
The input function will solve our problem.
This thing is designed to take input from the user or our customers,
and also fun to know whatever it takes from the user.
It will automatically convert it to a string,
which will become more important later. What we'll talk about that, but anyways,
let's see an action. So check it out.
So what we're going to do is use the input function to get our customer's name.
So actually we're going to remove this print function. Let's get it out of here.
We all need the print function anymore for this purpose. Anyway.
So take them out. Goodbye. We're gonna put the input function in his place. Now,
in order for our robot barista, to ask the question,
we're gonna actually put a string between these parentheses,
just like the pro function. So right there, we'll put what's is your name.
So now let's run it. I don't want to wait anymore.
Just click on run and let's see what happens.
What's what's happening.
Our script is still running and it seems like it's waiting on us to do something
because it is, it is it's waiting on our input or our customer's input.
So right here in our command line, it's just kind of chilling.
So let's answer it. Just start typing right there. I'll type in a Bob on Bob.
And we did it. We told our computer what our name was,
but that was kind of anti-climactic like, w what happened?
We hadn't seen anything happen from that. Yes.
The computer asked us what our name was.
And we were able to tell him we didn't do anything with it.
Now we could do this. We could actually print our input function,
which makes me feel like inception, but let's try it out real quick.
So let's just put prints around this I'll type print in front of input,
and then put in parentheses one before it one after it.
So essentially this is what's so cool about programming. Goodness.
The input function is inside of the print function. Now,
what do you think will happen here? Positivity to think about it. Okay. Resume.
When we run this code, what's going to happen. Let's go ahead and do it.
Click on run. So same thing as before, it's going to ask us for our input.
What's your name, buddy? Bob. And then it told us back it printed it,
which is cool in theory, but useless for our robot barista. What we,
wasn't your barista to go, Hey, what's your name? You say bobbin. He goes, Bob,
what good is that? But it is cool again,
that we can print our input function here and have the result given back to us,
but we don't need that. So let's take the print function off of it.
So let's move on and talk about how it can make our robot barista do something
with the name that we give it. So right after our input function,
let's do another pro function, enter a few times type in prince,
do our parentheses, and then we'll do a string. So quotes and I'll say, hello,
and I want the person's name to be here.
So I'm just gonna kind of put some filler here, some periods, pillow.
Thank you so much for coming in today. Instead of periods,
I could just put in Bob. Hello, Bob, thank you for coming in today,
but it might not always be Bob that comes in. I would hope so. Right?
I hope I have more than one customer than Bob. Uh,
it might be Susan or Patricia or Dave. I don't know.
How can we program our robot barista to say something like someone's name when
it varies? Well, you probably saw this. Kelvin will use something called a very,
a bull. You see what I did there? Anyways, here we go. Variables variables,
a variable as a method of storing data for reuse, for example,
a name we may want our robot barista to act,
to remember a name when the customer tells them.
So we'll do that here in a second, but first let's create a variable.
Let's just play with them real quick. So here in our code,
the first thing I want you to do real quick,
let's see if you remember this comment out, all your code.
So the robot barista we'll ignore it.
The way we can do that is by adding a hashtag or a pound sign in front of all
our commands or functions here, hashtag hashtag hashtag. Okay,
so now the computer ignores that we run the code. Nothing again.
That's handy to do when you want to just test out stuff and, uh,
have the computer. Ignore it anyways. So just blow all that type in this.
This is how we create a variable type in name, no parentheses,
no quotation marks. Just name that interspace equals space. And here,
I want you to put in your name as a string right after the equal sign.
But for me, I'll just put in quotations to make it a string network, Chuck,
and that's it. We just made a variable this right here,
name with nothing around it. Just a word is a variable.
And we set that variable equal to the string network. Chuck now real quick,
I want you to run the code and see what happens going click run that. Yeah,
you clicked it. And nothing happened, right?
Because all we did was create a variable,
but we didn't tell the computer to say anything or do anything to the computer
is very literal. He'll do whatever you tell him.
But it only exactly what you tell him. So now just below that,
let's print that variable. So do this type in print. Yeah.
You can print variables, put our print seasons. So we have our print function.
And then just between those just type in the variable name, just type the name.
No again, no quotations, no anything. And then click run. Look at that.
We created a variable named name.
We said equal to the string of your name in my case network, Chuck.
And then we printed the variable, which came out right here. Now again,
the key characteristic of a variable is that it can vary based on what you said
it two. So keep your same code here,
but just below it doesn't mean you can't watch this. Do this again, type a name,
that same variable name and send the equal to, I don't know,
iron man iron man, the string iron man. And then just below that code,
let's print that variable again. Print name.
What do you think going to happen here? Let's try it out.
Go ahead and click on run. Right. Whoa. How cool was that? Well,
here in our code, we define the variable name, set it to equal network. Chuck,
the string or the string network. Chuck. I said that backwards,
but then we changed our mind and set the variable name equal to Ironman.
And then we printed that. Okay. Now that we know how to create a variable,
what do you say? We use it for our barista robot.
Let's make him remember a customer's name up here. And here's how we do that.
It's going to remove our variable playground here. Just delete all that.
And let's uncomment our code here to remove those hashtags.
So it's back in action. Now I want to see if you can do this.
How do I set this input? Which will be what we tell the computer or our robot.
How do we set that to become a variable and store it as data?
Try it out real quick. Pause the video and pause. Here we go.
It's as simple as this right here in front of the input,
I'm going to type in name,
defining a variable space equals space. That's it.
When we run this code,
we're saying create a variable named name and that variable will equal
the input that we ask from the user. What? Yeah, no. Let's,
let's try it out real quick now to see that in action.
Let's real quick comment out our last print function.
And then just below the name variable where we set it. Let's print name now.
Let's see what happens. Let's run the code run. Hello.
Welcome the nurse at coffee. What's your name? My name is Susan bam.
So what just happened there? Well, it asked us for our name. We said, Susan,
the computer set the variable name equal to Susan, a string.
And then we printed the variable out, which is the string Susan.
So our next step is to use this in our ingredient. So instead of saying, hello,
Bob, thank you for coming in today. We want to say hello, the customer's name.
Thank you for coming in today. Hello, the variable.
Thank you for coming in today. Let's try it out now.
If you already know how to do it, do by all means,
pause this video and go try it out because it does involve a concept we learned
in episode one con cat nation or adding stuff together.
Now we only added strings together,
but you can add more than just strings together. Try it out,
but we're gonna walk through it right now. Here we go. Woo.
So remove the extra print function out of the way
and then uncomment our original print function.
So we should have it just like this. Uh,
first what I'll do is just remove the contents of this entire strings to start
from scratch. Start fresh. I'll start with the string. Hello. And then,
you know, the name will come after.
So let's just put a space there then to concatenate stuff.
We just use the plus sign, right? We're adding things together.
So I'll do a space plus space and then simply I'll type in the variable
name. Just like that. Also keeping in mind that I'm putting a space after hello,
cause remember the computer will literally print out what you tell it to print.
If you don't put a space there, it'll just say hello, Susan.
Like it's all one word. Come on computer.
So you got to tell it what to do anyway. So hello plus name again.
A variable has no quotations or anything on it.
And then we'll add another string to that. Plus start our new next string.
Put a space after that, but a comment.
Thank you so much for coming in today. Now this is so cool.
Let's go ahead and run this code and see what happens. Click on run.
It's going ask us your name. Okay. My name is Bernard. What?
We're good at? That's so cool. We programmed our robot barista to say hello,
Bernard. Thank you so much for coming in today.
And actually I put an extra space that shouldn't be there right before the COVID
let's fix that and run it again. Oh, better. It's gonna bother me.
How cool is that?
Now there is one thing I don't like about this and that's the input.
The question. What's your name? And then we end up typing our name.
Like no space right after the question, mark. That's ugly. How do you fix that?
Can you fix that for me? Real quick. Pause the video. See if you can do it.
I'm gonna fix mine right now. Right here in the inputs. I can do a few things.
I can just add a space right after that and that should fix it and we run that
code. So yeah. Now there's a space there. So does it feel so jarring?
So if I type Bernard will be right after that better, even better.
I could just instead of a space,
do a backslash N the lime break character. Let's try that. Oh,
new line. That's even better. Bernard. Perfect.
Now here,
I'm going to challenge for you and I'll give you the answer in this video,
but first I'm we can try it yourself.
I want you to program the robot barista to give the customer a menu,
ask them what they want, receive the information and tell them, Hey Bernard,
whoever it is, your whatever they ordered will be ready in a few moments.
And I want you to set that menu to be a variable. So can you do it? Try it out,
test it out. I'll wait, go and pause the video now on pause.
Let's try it out. So first let's create a quick coffee menu using a variable.
So I'll call my variable menu and I'll equal that a simple string,
nothing too crazy. I'll say black coffee,
espresso latte,
Kappa Chino is a how you spell it looks right. And that's good.
So right now we've got a variable menu. It's equal to everything on our menu.
Now let's have a robot barista ask the customer what they want and give them the
menu. So here we go. There are a number of ways to do this,
but I'm going to do it this way. First. We'll do a print function, prince.
And I'll say the name variable. That'll add a string to it. Comma.
What would you like from our menu today?
Here is what we are serving and the right within that string.
I'll do a line break and then I'll add something else to this.
I'll add our menu.
So this should say the variable name, then the string.
What would you like from our menu today? Here's what we are serving.
And then it'll say the variable menu. Let's try it out. Let's run this code.
Hello? What's your name? My name is Susan. Oh, how cool is that?
I'm going to add some extra space right here. Oh, it looks a bit more clean.
So I'll add that in that print statement. See how it looks now, Susan,
get that looks better. So now let's get the input from our customer.
I'm gonna create another variable. I'll name it order.
And I'll have that equal input. Uh, for this. I don't have to do anything fancy.
I'll just keep the input like this.
That's not going to print anything or say anything,
but it will still expect input from the user. Let's try it out.
Let's run the code. Bernard is my name. And now it's waiting for me to answer.
I'll see. I don't know, latte. Cool. So it took the input.
Now we have to do something with it. We have to do something with our variable.
Let's do our next print statement. And this is our final task in the, uh,
the project here. I'm going to print. Sounds good.
Then I'll add the variable name. Then I'll add string. I'll do a comma.
We'll have that.
And then I'll add the variable order and then I'll add another string right
after that, which looks crazy. Right. But it's going to be so cool.
Ready for you
and a moments now that's a lot of stuff going on. It's so cool.
Because right now we're adding three strings and two variables together in
one print function, which is nuts. Let's go in print. Let's do it print.
And here's our complete script. What's your name? Bernard. Here's our menu.
What would you like? Hmm, definitely a black coffee. Sounds good.
Bernard will have that black coffee ready for you in a moment you go robot
barista. You're doing so good. I'm going to give you a tip now.
Real quick challenge for you. I know we got a lot of challenges, but one more.
And I want you to comment below with the answer.
How would I combine these two parts of the script right here?
Let me know who episode two, coming in strong. We learned two big things today.
First, the input function, how we can,
instead of just saying things to our customer or the user,
we can actually request data from them and have our robot reach to do something
with it. How cool is that?
But it's useless unless we can remember that input and do something with it
later in our scripts, which brings us to variables.
And we used both of those powerful concepts to create a robot barista,
which is really cool right now, but we can make it a lot more amazing,
a lot more powerful, which we'll do in the coming episodes. But anyways,
that's all I got for you today.
Let me know what you think in the comments below.
Make sure you hack YouTube today. Hit that like button subscribe, comment,
notification bell. You gotta hack YouTube today. Ethically of course. And again,
a massive shout out to the sponsor of this entire series and the reason it can
be free here on YouTube. It pro TV. Oh,
and also I've got a quiz and a challenge lab for you to test your knowledge of
episode one and two so far. Can you do it?
The first five people will solve it and we'll get a free gift card to never
chuck.coffee. Let's see what you got. If you want to get started in it,
or you want to further your career, they are the place to get your stuff done.
Check it out. Link below. Use the code network, Chuck and get 30% off forever.
Yeah, that's all I got to the guys. I'll catch you in episode three.
[Inaudible].