 Welcome back everyone this is Brian we're going to create a simple application using everything that we've learned to this point if you're just now tuning in there are 13 other videos in this playlist you need to go back and watch if you don't know Python, but we're going to make a paint calculator. So we're going to determine how much paint is actually needed to paint a room. When we run this the user is going to be presented with something like this paint calculator in our wall size as width comma height in feet or press enter to stop. For the example would be 12 comma eight no spaces or anything like that. And they can enter as many walls as they want and at the end of this is going to magically tell them how many cans or how many gallons of paint they need to go by. Let's take a look. First thing we need to do is well set up some variables so we're going to make a list called walls and this list is going to exist just to hold the measurements. Second thing we're going to add is gallons. This is going to be well how many gallons of paint per square feet and I'm not an expert. But I did go out and look this up on Google. And according to Google one gallon of paint covers 350 square feet. I question that because every time I have bought paint I have never bought enough and I've had to go back to the store and get it maybe this application helps. And then total is going to be the total number of gallons of paint we need to go by. We're going to use this later. Little gallons to buy. So far our application does absolutely nothing but that's about to change. We are going to get the user's input and we haven't talked about this yet. But we're going to make a while loop. We're going to say while true and you may be going to whoa whoa whoa. You're making an infinite loop. That's true. We're going to break out of this and I'm going to show you how. So we're going to get a variable. And we're going to use the built in input functions. There's different ways of doing this but we're going to use input. And I'm going to say enter it long size. Then we're going to break out of this if they don't really enter any data. So I'm going to say Lynn of s is zero. Then we want to just call break if you kind of questioning what any of this is go back and watch the previous 13 videos that I've done on this. So let's go ahead and test this out. We're going to run this and it says inner wall size. You know how our programs just stopped and waiting for us. Well, I'll just enter some garbage. I'm going to say cats. And it wants another. And another fish. And then I'm just going to hit enter. And sure enough, it exits out. So that is the correct way of using an infinite loop to gather user input. And to test when we need to break out of this loop. Now that we can get the user input, we need to actually do something with it. And before we try to do anything with it, the first thing we should do is well verify that what the user gave us is actually what we're hoping for. Or we could have a very bad time. Remember this whole thing started with the example of 12 comma eight. Well, I entered cat stocks fish. I'm not sure how you would calculate the square footage of a cat, but I'm sure it would be interesting and probably involve a trip to the vets. But anyway, so we're going to say sqft equals and we're going to say s split. Because the s is our variable we got from the input function right up here. And it's going to be a string. So we can treat this as a string and say s split. And we want to split this on the comma. Again, if you have not a clue what I'm doing here, watch the previous 13 videos. But anyways, string has a built in function called split, which you can return multiple values based off a character or sequence of character. So our square footage is going to be the return value from that split function. So first thing we're going to do is make sure we actually have two values in there. And if it's less than two. Well, we want to tell the user something bad happened. Print. Let's go ahead and just say invalid format. And then we're going to break out of here. Now remember break doesn't really care where it is. It's going to break out of this loop. Let's go ahead and test this out here. So we're going to run this and it's going to say inner wall size. And I'm going to say, okay, two comma six. It's working good five comma seven. And let's enter some garbage cats. Oh, invalid format and it stops a loop and exits the program. So it is actually testing to make sure there are two items that is split on a comma. All right, we're not done yet. We need to now that we've gotten the user input converted because remember we're working with strings and we want to work with numbers. Specifically, we want to convert from a string to an integer. And this could lead to a bad time. And we're going to demonstrate that. So I'm going to say w equals, we're going to call int and we're going to do something called casting. And I'm going to do a whole video on this later. But when I say casting, just think of a wizard with a magic wand who's going to cast a spell and turn something into something else. So what we're saying is we want to cast a spell called int, which is going to convert whatever we give it into an integer. And in this case, we are going to get that first value out of square footage. But grab this, give it the old copy paste, a little too much copy paste. And let's get the other dimension. So now we have the width and the height from square foot zero and square foot one. Interesting bit, if we try to do this and it's not actually a number, we're going to have a bad time. It's going to actually air out and our program is going to stop and die a horrible death. And I'm going to cover how to handle all that in another video. The whole point of this program is to do a program with what we've learned so far in the 13 videos. Now I'm going to say item, and I want to make a list with the width and the height. And we're going to add that to our walls. And if you're wondering where I got walls from, remember, it's way, way, way up here in our variables, just an empty list. So we're going to say walls and let's go ahead and add that item in here. So now we have a list holding the wall dimensions for every single wall that they add. Let's go ahead and just print that out just to verify, hey, we did something. Adding wall, go ahead and save, run, and let's test this out. So inner wall size, all right, three by six, it's a very small wall. And it says adding wall, all right, great. So eight by eight, let's go ahead and say nine by 12. Now let's test out this conversion right here and watch it die a horrible death. So I'm going to say two by cats, and valid literal for int with base 10 cats. And this looks very ugly, and it is, it's a value error. We're going to talk about errors in a future video. I just want you to understand if you get a value error, what's going on is we're basically saying we cannot convert this to a number or specifically to an int. Remember, think about wizard with a magic wand and we are casting a spell called int, which is going to convert whatever we cast on to an int. Once we've gotten to this point, the only thing that's left is to really just crunch the numbers and tell them how much paint they need. So what I like to do is just tell them what they entered. So we're going to say if you entered that way, if there's any discrepancy, I can say send me a screenshot of the app and I can show, oh, no, no, you screwed up, you entered the wrong value here. And then we're going to say for M, M is going to be for measurements in walls. We're going to say the width is going to be M zero. Remember, it's a zero based index. And inside of our walls, we have created another list here. So we're getting this guy, the width. And we can say H one, remember zero based index that always trips newbies up. Now we're going to get the square footage. So I'm going to make another variable called s. I'm going to say that simply the width times the height. Now I want to get some sort of value. So I'm going to say this is the s or the square footage times the gallons. If you're wondering where gallons magically appeared from, remember, it's all the way up here in our global variables that we created. I did Google it. One gallon should cover 350 square feet. So this value right here is one divided by 350. Not a clue if that's accurate. I highly doubt it, even though I do trust Google. And then we're going to grab our other global variable total. I'm going to say plus equals V. So we're just incrementing that. If you're wondering plus equal, we did cover this in a previous video. It's basically we're saying total equals total plus the value. But we're just short handing it. Now we're going to drop down and go inward. We're going to dent in. So we're dropping out of this code block right here. And we're going back to the main. We're going to say print. We're just going to tell them you need to go buy some paint. And this is how much paint you need to go by. You need to buy. Let's go ahead. And if we just say total, it's going to give us some crazy number. So what I like to do is make it a little pretty. And I'm going to say round. And we're going to round the total by two decimal places. We're going to tell them you need to go by our many gallons of paint rounded to two decimal places. Let's go ahead and test this thing out and see if it works. So I'm going to say 12 by eight. And let's make another one 15 by nine. Actually, let's make it by eight. That'd be weird if the ceiling was different height. And let's go ahead and say we have an eight by eight and a four by eight. Just kind of a weird shape room. And then I don't want to enter any more. So I'm just going to hit enter and you need to buy one gallon of paint. Basically, it's going to use less than a gallon. I should have some leftover. I don't know how accurate that is. And honestly, I'm kind of looking at my little office here going, I think it's going to take more than a gallon to do this. So when in doubt, blame Google. But the major takeaway from this video is even though we're only 13 videos in and we've really just scratched the surface of what Python can do, you can make some pretty interesting programming logic. We just did a simple application, which is a paint calculator telling us how much paint we need to buy. We're letting the user enter any number of walls they want. We are verifying that user input and then we're converting that input into the correct data type. And then we're calculating how much they need and giving it back to the end user. I hope you enjoyed this video. You can find the source code out on github.com. If you need additional help, myself and thousands of other developers are hanging out in the Voidromes Facebook group. This is a large group with lots of developers and we talk about everything technology related, not just the technology that you just watched. And if you want official training, I do develop courses out on udemy.com. This is official classroom style training. If you go out there and the course you're looking for is just simply not there. Drop me a note. I'm either working on it or I will actually develop it. I will put a link down below for all three of those. And as always, help me help you smash that like and subscribe button. The more popular these videos become, the more I'll create and publish out on YouTube. Thank you for watching.