What I use to learn (the BEST IT training): https://ntck.co/itprotv (30% off FOREVER) *affiliate link
FREE Python Lab: https://ntck.co/pythonep1
Support the course: https://ntck.co/pythonrightnow
🔥🔥Join the NetworkChuck membership: https://ntck.co/Premium
**Sponsored by ITProTV
0:00 ⏩ Intro
0:57 ⏩ What you NEED
1:54 ⏩ recap – Strings and Variables
2:12 ⏩ Numbers in Python – Integers
2:34 ⏩ Verifying data types with the type() function
5:30 ⏩ Floating Point Numbers
6:40 ⏩ Python calculator
10:26 ⏩ CHALLENGE!! (Robot Barista)
14:22 ⏩ the int() function (converting data)
16:36 ⏩ the str() function (converting data)
Just when you thought that Python couldn’t get any cooler, you find out it includes numbers and math. Yes. Are you kidding me? No. Seriously. It kind of had me worried there for a sec because I wasn’t a big fan of math in school and math. Wasn’t a big fan of me. I, uh, I wasn’t good at it
You Don’t have to be good at math to learn Python. And the math I’m talking about is like stupid, simple, like one plus two equals four simple. And it’s this simple math that we’re going to learn here in this video that makes Python so powerful. Maybe math, wasn’t fun for you in school, but it’s about to get lit with Python. Trust me. It’s going to be awesome. So here we go. This is episode three of my free Python series, where I’m going to teach you everything you need to know to become dangerous in Python episode one and two, we covered some stuff like strings and variables, and we had like seven cups of coffee or was that just me? I hope you joined me in that. And now we’re going to build on that knowledge and have even more coffee. So let’s dive right in, but first, what do you need? Well, if you’re new here, you need nothing. I’ve got a free Python lab. Check that link in the description. You can start coding right now from your browser or even man, your stinking phone. And also you’re going to need coffee. It’s just required,
Never checked out coffee. And also a massive shout out to the sponsor of this entire series. In that reason, it can be free here on YouTube. It pro TV. I use it pro TV to learn everything in it from Linux to networking, to hacking. And you guessed it by thoughts. So whatever you want to learn in it from a CCNA to a plus to everything, they got you back. They got fantastic videos. Hands-on labs, practice exams, pretty much everything you need to get started in it or advance your career in it. So check it out, link below and use my code network, Chuck, and you’ll get 30% off forever. Let’s get started. So just like episode one and two, go ahead and fire up that lab. Check that link in the description. Load that sucker up and we’ll get started. Cause we got to do this hands-on you got to start coding with me right now.
Best way to learn. Okay. So far in this course, we’ve talked about two very big ideas in Python, the variables and strengths. So go ahead with me right now. As I’m typing this type it with me, create the variable name and then assign that variable. The string of your name, try it out. Do a mine here. There’s my variable. And there’s my string string. We know what the stream, because it’s between quotes. No, it’s a variable because it ain’t got nothing, man. Now let’s talk about numbers. The first type of number we’ll talk about is our good old whole number. It’s the first thing we learned in math, right? 1, 2, 3, 4, 5, as we’re also going to learn here with Python and Python, a whole number is referred to as an integer because they just have to be different non skinny. Well kind of that’s what it’s called an integer. Let’s go make one right now. Come on, let’s go. You ready? It’s super complicated. Watch this. I want you to create the integer seven
Done. That’s an integer right there. If I were to run this code, it’s fine by clicking notice though, I don’t have anything outputting. Cause I don’t, I’m not telling it to, but that is indeed an integer AKA whole number. And really it’s that simple. Now, just like we can assign a string to a variable. We can also assign a number or an integer to a variable. So why don’t you do that for me right now, assign that number seven to a variable named age. I’m going to do it. And it’s very simple. Age equals seven. Now I’m not seven. So I’m going to fix that real quick. I am 31. I’m getting old man is more coffee. Just thinking about that.
Now let’s go ahead and print those suckers out. So just below all that code here, we’re going to do print we’ll print our variable name and just blow that we’ll print our variable age and let’s run that code real quick run. Awesome. Never Chuck 31. Okay, cool. We’ve got two data types here. We’ve got a string and we have an integer. Awesome. Now real quick. I want to show you a handy way to identify what type of data we’re looking at. And it’s a function called type. Literally. It’s what it is. You’ll type it in like this type and then parentheses and whatever the variable is or the data is you’ll put it in between. So for example, if we wanted to find out what type of data the variable name was, we would type in type and then put name. Let’s try it out.
So just below all this junk, we’re going to do type for emphases and then name. Now, if you run that code, we’re not going to get anything going click on run. Nothing because we got to print that out. So I’ll just put the print function around that prince and the parentheses around that. So now I’m using the print function to print the type function, just programming. So cool. Anyways, it’s going to print that. So now right here in our output, we see the class is STR or string. Let’s do that same thing for our integer and see what happens. Spoiler alert. It’s going to say it’s an integer, but let’s just try it out. Print type age and we’ll print that sucker out. Boom. Okay, cool. Just had to prove it to you. So you know, I wouldn’t line strings and integers right there. Now I want you to do something for me.
Let’s do a little, little experiment here. I want you to add quotes around this energy right here around 31. Do it. Let’s do it right now. This is gonna be cool. All right. So quotes and quote. So now let me ask you a question. When we do run this code here and we try to find out what type of data age is, what’s it going to say? Now that we’ve added quotes, let’s try it out. Go and click on run. Ooh, did you see that coming? Both of them are now strings because remember anything between quotes is a string. Even if you put a number there, that number is now seen by Python as just regular text a string, knowing this is going to come in handy here in a moment when we keep working on our robot barista. Yeah, I didn’t forget about him.
Did you? We’re going to keep making him better. So real quick. I want you to take those quotes off now because we want that 31 or whatever yours is to be a number you’ll by the way, you can put network Chuck and 31 here. If you want, as you want to be as old as me gross. But anyways, um, just like math, we also have decimals, right? So let me type in a new variable here. I’ll do actual underscore age equals am I real age in decimal point is actually 31 point 96 and yeah, my birthday is coming up. Can you figure out what it is? Let me know. Now, as soon as we add that decimal to our number here, our integer it’s no longer an integer it’s now what’s called a floating point number or float for short gosh, that made you want to rip beer float through real quick.
Let’s actually print that type out just to see what it looks like. So I’ll do print type and then that variable actual underscore age. And let’s do that, print it out or run the code. Right? Men look at us. We got three data types in Python. Now string integer. Was that an arrow? Let’s fix that. Let’s go and float. AKA, just text whole numbers and decimals. Now again, normally when you start talking about numbers, you’re going to start talking about math, right? And yes, there is math. Actually. You could use Python as a calculator, like watch this. Let’s remove all this code right here. Just go in here and delete it. So right now when we run this, nothing’s going to be outputted because we’re just setting or assigning variables here. So let’s do some Python math. So do this real quick print five space plus space seven.
What do you think’s going to happen there? Let’s try it out. Let’s run the code. Run simple enough, right? It did math five plus seven here we have the integer five and the integer seven and we added them together and we printed it out. We can also subtract five minus seven, negative two. Yes. Negatives can be integers. We can also divide with the Ford slash we can multiply with the asterisk. We can even do five to the seventh power exponent. We can even do all of that in one print function, plus six divided by nine times seven or I type six times six minus four. Let’s run it. Now. You’re probably not surprised that Python can do math cause mean computers. They’re pretty big on math. They love it. It’s kind of their love language. And also in case you were wondering, Python does follow the order of operations.
So dust off the cobwebs of that math knowledge and try to remember that or just Google it. So we’ll do exponents first multiplication. You know how it does just math stuff, but it is important to remember that. Now we can also set that entire equation to a variable. I’ll create a variable name to math and have that equal, all that stuff. If I run that code, of course, it’s not going to show anything cause I’m not printing it out. Let’s print out math down here, prints math, and let’s run that. Cool. Now real quick. I want you to try this first, make sure you do have these variables in place. So your age, trying to figure out your actual age, there’s a website actually called, uh, agent al.io, kinda neat, and then type out some kind of math problem or equation and set that to the variable math.
Once you do that, I want you to add all those variables together and set it to the variable results. Pause the video. I’ll wait and unpause. Let’s try it. So to do this first I’m to move that print function, we don’t need that right now. I’ll define my variable results. Have that equal. Now it could go through here and painstakingly type in each number, but we don’t have to do that. We can just simply type in the variables and add those variables together. So I’ll say age plus actual age plus math, and then let’s, uh, print out those results. So print the variable results and let’s see what happens. Bam. We added them together. Now pop quiz that result or the variable results. What type of data is that? Do you know? Well, if we can look at the results and we know that there’s a decimal right there, we know a decimal is a float or a floating point number and fun fact, any time Python divides or uses division, it will convert those numbers.
It’s dividing into floating point numbers before it divides and the result will be a floating point. So anyways, what we’ve covered so far is that you can do math and Python. If you want to add it’s a plus side, subtract, it’s a minus sign. So stuff that you probably intuitively already knew, right? Multiply. It’s going to be that asterisk divide Ford slash and then exponents, which this one may not have been too obvious, double asterisk, eight to the power of 25, whatever you want to do. So now that you are armed with the knowledge of Python math, we can add some features to our robot barista because as it stands right now, our coffee is free and uh, we’re losing money like crazy. So we had to actually start charging our customer some money and to do that, we need, we need math. So go and open up the second lab for this episode.
Yet two labs. Yes, yes, let’s do it. We’re going to modify our network coffee script. Let’s do this quick recap. We’ve expertly programmed him to greet our customers. We then program him to ask their names and they can tell him and he’ll remember it because we assign it to a variable. He then greets them with that name, gives them a menu. He will ask them what they want. They will tell him he’ll remember it and tell them it’ll be ready here in a moment. Let’s run it real quick. Just for fun, because it is fun. Run. What’s your name? My name is Beatrice. I would like a latte. Thank you, robot barista. And it’s gonna be ready in a moment. I’m so at home, but we’re losing money. Let’s charge some money real quick. Now here. I want to see if you can do this.
Let’s let’s challenge you a bit. Here are your tasks and then we’ll walk through it together. Task number one, first, create a variable named price and assign an integer. We’re setting our price for each coffee and just keep things simple. Everything on the menu is the same price. Now for me, I want to set mine to $8 because we’re fancy man. Never shucked coffee is good. Anyways, you can set it to eight. If you want. It doesn’t have to be eight tasks. Number two, program, our robot barista. We’ll call them RB for short robot barista to ask how many coffees they would like and also make sure he remembers how many they want. And finally task. Number three. Now keep in mind. This can be done various ways each step can be done for all. Step one is pretty straight forward. Step two and three can be done in a number of ways, as long as you accomplish it.
That’s cool. Step three or task three program RB robot barista to give them their total, the total cost of all the coffees. So right now, pause the video. See if you can do this, add this to your script. I’ll wait and unpause. Here we go. First. Let’s fuel up again. Python. Math. Just when you thought you were done with math and school here, it comes again, but it’s okay. It’s still fun. Well, it’s it. Wasn’t a fun before. It’s fun now though. So our first thing is to figure out where in our script do we want to ask them? Well, it looks like right here after we set the order equal to input. So first let me set our price. Our variable will be named price, have the equal to, and again, it was going to be $8. So just simply eight. Now I will say this as we’re doing this and you may have tried this already.
There’s a little gotcha. There. You may have hit this error and we’ll talk about how you can fix anyways. This solves a task. Number one, test number two, robot barista needs to ask our customer how many coffees they want and remember it. So that’s going to involve a variable and the input function, I’ll name my variable. And you could have done whatever you want it to I’ll name mine. Quantity. I’ll have that equal the input function. So in book, because we want to get some information, some data from our customers and we’ll ask how many coffees would you like? And then I’ll put a space after that to make sure it looks pretty. And actually, you know what? I’ll do a I’ll space. I’ll do a line break with our backslash in new line indicator. So now at this point we get our price variable set.
We’ve got our quantity variable set, which we’ll get data from our customer and the robot barista. We’ll ask them for it. Now let’s do some math because now the robot barista has to tell them their total. Now again, you could have done this a number of ways and maybe you did hit a hiccup and we’ll talk about that, but I’m gonna start with this. I’m going to start with calculating the total. I’m going to do a variable for that. So I’ll say total and I’ll have the equal. And then here’s, here’s where the math comes in. The total will be the price of coffee, right? Times however many coffees they want. So let’s do that math here in our variable. So I’ll say price times, quantity, that should work, right? You would think not to check our math. Let’s print the total. So I’ll do print total.
So I’ll print the total variable and let’s see if it works. Let’s go ahead and run the code. We’re run through real quick. My name is Patricia. I want black coffee. I want 10. Cause um, I want some energy today. Well, what just happened there? So what we wanted to happen was we wanted eight times the quantity, which we typed in 10, which we know based on simple math skills, it should be 80, but instead we cut eight tens. Why? Well, because of this, when you use the input function, whatever data it asks you for that data is not going to be a number. It’s not going to be an integer. What do you think is going to be it’s going to be a string. So when we told, we told robot barista to multiply price by quantity, he multiplied the integer eight times the string 10.
So he literally gave us eight tents, which has got a funny, right. But how do we fix that? Because it’s not funny. We’re trying to run a coffee shop here. How do we fix that? But what we need is for the input function, the data we received from our customer, we, when we that not to be a string, we need that to be an integer. Don’t we new concept time. Here we go. You can convert data easily like this. Oh, it’s so cool. Watch it. It’s so powerful. You’re gonna use this all the time. Trust me. And we can do it in a number of places, but I want to do it right here because it’s very clear when you do it here. Otherwise I’m doing like this. Like we’ll make this very clear. Anyways, here we go. So here in our total with our math equation right now, we’re multiplying an integer with a string.
Let’s change that string into an integer. We can do it like this. We’re going to wrap them up. So watch here, right here with our quantity variable. I’m going to type in I N T and then parentheses, but parentheses around him. Bam. What we just did here is pure magic. This function right here, this int function or entity, your function turns whatever’s in the side into an integer. So now theoretically, if we did it right, we’re multiplying integer by integer. Let’s see if it works. It’s run our code, run, walk through it again. My name is Ben. I would like an espresso please. I want 20 fingers crossed civil works. Bam. Yes. Okay. We successfully converted our string into an integer for the sake of math. Yes. Cool. So we accomplished task one and task two, but now task three. We have to make our robot barista tell our customer that they have a total.
So just under print total, actually, we’re going to remove print total. We want him to actually say something human-like so we’ll say print. We’ll do a string. We’ll say, um, thank you, period. Your total is we’ll do a colon and a space. And then we’ve been here before. We’re going to concatenate. We’re going to add some stuff together and our print function add some strings. So we’ll do plus space and then we’ll do total. The variable. Now more foreshadowing. This probably is not going to work. Do you know why though? Do you know why this won’t work? Let’s run the code and see what happens. Click on run. What’s my name, Tom riddle. I want a cappuccino. I want 70 cappuccinos. Whoa, error. Ooh. Get used to it. This can happen to you a lot. Now let’s take a look at what happened here. We have a type error.
Now we know from earlier that when we are talking about type, we’re talking about type of data. When we use our type function, it will tell us what kind of data it is. So same type error robot. Barista can only concatenate string, not integer to string. So what he’s saying here is that, Hey, I can add a string to another string, but bro, he threw at me the problem of a string plus an integer, which equals can’t do that. I’m confused. I don’t know how to do that. We have the reverse problem now don’t we earlier, when we did our math problem, we needed a string to become an integer. Now it seems we need an integer to become a string. See if you can solve this, using the same mentality, the same pattern that we just followed. See if you can do. It’s actually crazy simple.
Now. Whereas earlier, when we wanted to convert our string into an integer, we surrounded it with the int function. Just like, so turning it into an integer. We can do the same thing, but instead of int we’ll do STR for string to that same variable, just like that. Let’s try. Let’s try now. It’s not going to be quantity, right? It would be total. So it’s going to be total right here. Right here on total. I feel like I’m saying Toto, total typing STR parentheses and we’ll wrap it up both sides. So now we should, at this point, be adding a string or concatenating, a string with another string. We’re converting this number, this endanger into a string. Let’s run the code and see what happens. Hello? I am poppy. I would like a black coffee please. I would like over 9,000 coffees please. Ooh, we got it. We got it. It worked. So take that in for a second. We convert a string to an integer and then an integer into a string. That’s programming man. That’s programming anyway. Sorry. I’m getting a little I’m way too. Hopped up on caffeine. Coffee break.
Now that is some coffee bill. 72,000 business is good now real quick. There’s no dollar sign. Let’s add a dollar sign to it. Now, how would you do that? How would you add a dollar sign to that statement? Well, it’s pretty simple, right? We go in here and within that string, let’s say like right around here, put a dollar sign. Let’s run it right? Hello. My name is John Hammond. I would like an espresso. I would like 8,000 espressos please. All right, now we’re talking money. Now. One more task for you. I want you in this last statement for the robot barista staying. Hey sounds good. John Hammond we’ll have that espresso ready for you here in a moment. That doesn’t sound right because John Hammond wanted 8,000 espressos and we’re only seeing one come on, robot barista, get your head together. So I want you to throw a number in here.
Say sounds good. John Hammond we’ll have jeez, that vet to a, your we’ll have your, that. Will you say your 8,000 or however many you type in espresso’s ready for you in a moment. Let’s do that real quick. That’s pretty simple. It’s using skills and tools. We’ve already learned. So down here, whereas this sounds good. Let me say, plus the name we’ll have that order ready for you here in a moment. We’ll change the, that to your we’ll have your, and then we need to add another thing to this. We’ll add the quantity and then we’ll add one more string after that. And it will simply just be a space character that way it’s nice and pretty well let’s run that code. See if it works, Ron, my name is Nick. Nick likes black coffee, 92,000 copies, please. That’s some Coffeyville man. Good job robot barista now.
Sure. Black coffee is not implorable. We haven’t got to how we can do that yet, but man, this is beautiful. Our robot barista. He’s a champ who, okay. We, we did a lot. We learned some Python math, which normally math sucks. I think we can all agree with that. Right? But math and Python much better. So here we learned the new data types. We learned about integers, which are whole numbers. We learned about floating point numbers or floats, which are decimals. And then we saw how we could use math, basically treating Python like a calculator and do some cool stuff like adding prices to our coffee shop, who, who were thought to add prices to coffee. And we did some crazy things like converting into Jersey, into strings and strings and integers. Dude, we’re doing some cool stuff and we’re just getting stuck in case you were wondering.
Yeah, Python does get way, way cooler than this, but I hope you enjoyed this. Let me know what you thought. The video in the comments below, make sure you continue to hack YouTube by liking this video and hit that notification bell and subscribing you get a hack YouTube today. Ethically of course, and again, a massive shout out to the sponsor of this video and this entire series. It pro TV, who again, I use to learn everything about it and you should too check them out using my link below or my code network, Chuck and get 30% off forever. You thought that can take forever. It didn’t you. Oh, and also I’ve got a bonus quiz and an extra land for you if you want to try it out and keep going. So check it out. Link below. And the first three people to get a hundred percent on that quiz. We’ll get some free network. Chuck coffee then. Yeah. That’s pretty much all I have today. Ooh, Python’s amazing. I think we can all agree and thank you Don for making math. Cool again, or I’ll catch you guys next time.