 Okay, cool. Hi guys. Welcome to build your own pipette. I'm Tatiana This is gonna be a fun tutorial for Python beginners and novices as well as a kind of argument for project-driven learning And yeah, so you can see the slides right now. I made a nice bitly link So it's like super easy to find I highly highly recommend going there cool So learning a back-end language can be really hard. I think it's for this is for a couple reasons one is that it's Not visual like hello world in HTML is like the easiest thing to do right you like create a text file You open in a browser no complex setup. You see it right away Again, yeah, not a lot of complex setup when you're getting started on in the front end But back-end tends to be a little bit more setup heavy I also think that there's not that many terribly exciting examples But I'm also a very like excited excitable sort of person. So might just be me but yeah Okay, so so why why is why are back in languages? Why is learning like this so hard right now? There's kind of like two different ways a Lot of people Start building things from scratch and I think and build these up the right way which is amazing And when you when you finish doing something that way like you really understand that project or that concept super well Right the cons are when you're new. It's super intimidating I mean people have just given up on learning Python or other back-end languages because like these initial projects that That that going from complete beginner to like building stuff level is so hard on the other hand What I'm gonna call like sandbox learning think like code Academy The the pros are like yeah, you have success right away immediately code Academy is like awesome You get a badge cool But the cons are that it's not really useful for real life And you're not using your own tools and I've had many people talk to me after finishing code Academy and being like Okay, I don't feel like I learned some stuff, but I have no idea like what to do next So hopefully this this project I go over today is gonna be a nice kind of in-between step So yeah, the happy medium My pipe example hopefully falls in between these two extremes with just enough simplicity to not get you like off Success simplicity does not get you too frustrated But also it's a great opportunity to actually have your own setup and be building a project that you feel is like a real Project that you can like show off to people and you're gonna be like really proud of and excited Cool bonus. I like making things as fun as remotely possible. So I tried my best guys see see what you think Okay, so this is kind of a workshop even though it's a talk to So if you want to follow along I highly recommend it So yeah, open up a text editor and I'm just curious in the room Who is like not a beginner or would not consider this as a beginner? Okay, cool you guys are awesome if you want to find someone who is more beginner and like sit near them I'd love to encourage talking and like being friends, but you can also just do your own thing to totally fine Cool and the cool thing about this is even if you are not a beginner If you care about education at all the talks can be valuable because you're gonna learn how people learn or you're gonna understand That process better. So cool. So the final code of this project is at my github Get up comm slash hotty slash pipette. I recommend going there if you get confused or lost But I'll try and walk through the examples pretty slowly I'm also gonna try and code it with you guys if that proves to be too long I might just switch back to the slides, but either way. I'm excited Okay, so This was called build your own pipette and then I was like, oh wait Pokemon go I can make a Pokemon go theme cool, and then I try it. I was like, okay Pocathon Python I'm on and like nothing worked But if you guys can think of something really cool just tell me at the end of this talk Okay, this I'm gonna just play music for like five seconds just so you get the full effect of Okay, hold on. It's so worth it with the music you have no idea Music or if someone else has it open they could play it. Okay, I got it Literally just wanted a tiny bit from my phone. It's totally be enough Loading over data. Cool Okay, welcome to pie Gotham. My name is professor Van Rossum People affection refer to me as the banana like this data for life You can if that you don't get that reference click on that link. It's funny this world is Inhabited far and wide by creatures called pipettes Okay step one guys choose your pipette. I will turn down the thing is like just wanted you to experience that It's full. Okay. So step one is to choose your pipette I do recommend that you don't use ASCII characters for right now, but that's a bonus feature that you can figure out later Okay, I'm gonna do the actual Python So like I said, I'm gonna do this with you guys from scratch if it takes too long then we won't do it So I've selected my Python. I'm gonna do the snake. It's cool So part one printing your pipette Python's print function allows you to see valuables in the terminal when you run your code Again, this is like it's cool to actually have some sort of visual aspect when you're first learning So that's really nice. So go ahead and open up any text editor and write the code You need to print your pipette in this case pretty simple print and then just in a string Which we'll learn about later. You're gonna copy and paste your pipette from that other slide. So I'm gonna go ahead and do that now. Oh Sorry Okay, okay cool Awesome and then now go ahead and save the new file as pipette dot PY for me. I'm gonna save it as pipette To dot PY awesome And now in order to run this You need to open up your terminal and again I know I'm a little bit biased like this is mainly for Mac people and I'm really sorry But if you aren't using Mac, I highly recommend using nitrous.io They have a free trial where they have like a really great in like a just a terminal and the code right there And you can just run it and it's like being in a normal Environment, which is very cool. So yeah, when I'd save that and now I'm just gonna do Python Whoops, Python pipette To why okay, I printed out my my pipette guys Okay part two variables variable store of values Some example variable possible variables include strings integers both floats and booleans You're going to both. So right now. We're gonna add some variables for our pipette, which is really cool We're gonna give this we're gonna make this his photo Obviously very beautiful photo And okay and name. Oh my goodness Let's see Awesome, I was gonna call him. He's pretty epic. So he's a big name Cool and then so this is an example of a string now when I do something like his age I could make age equal to five But that would actually still be a string if I want to make this an actual integer so that Python recognizes that it's an integer I just don't use the quotes and it goes as an integer, which is really cool Okay, and then we're gonna do wait if you want I mean you can also feel free to add other stuff But I'd recommend kind of at least doing these as a minimum and we're gonna do this We're gonna make a value called hungry, which is gonna be a boolean So booleans can eat can have one of two values true or false. So he is let's see. He's totally hungry. So I'm gonna say true for now Cool, so the next thing I'm gonna talk about is so you've noticed I talked about a few variable types right there That's gonna be important because when we want to like actually print out these variables It's really easy to print out like his name. I suppose a print. Oh, sorry. No wrong. Sorry So I say hello, it's and then if I want to print out his name I do plus and I type name. It's really that simple. So I'm gonna save this I'm gonna go over here and I'm gonna run it once Hello, it is the Python King Yeah, cool, but now say for example, I want to print out his weight So this is where it gets a little bit weird So because weight is not a string when you're concatenating it You want to turn it into a string using this little super-duper awesome function that comes with Python and Yeah, so now when I save this and I run run my Python script over here They'll say Python King weighs 5.5 pounds. I think it's pretty heavy for a snake. I don't know cool So yes, I think on So if statements if statements allow you to check a condition and see if it's met or not met For example, if his age is greater than four or if he's hungry or not So we're gonna write a really simple if statement to just check and see if he's hungry So and again Okay, so right now this this if statement is just checking this boolean And if this boolean is true, which we know it is because up here We set it to true. It's gonna print this statement if it's not true. It's gonna print this statement So we go ahead and run it over here. It says your pipette is hungry. Oh my goodness But if I go over here and I change this to false and Run my code. Oh Okay, cool Just kidding guys. There we go. Excellent. Okay, your pipette burps loudly. I don't know if snakes can really burp But regardless Cool and You can feel free to make any additional statements about your your pipette as you choose Awesome so part four is about is functions. So as you can see our code It's kind of messy now. Look at what I've got. It's just like a bunch of random stuff hanging around So functions allow us to organize our code into reusable blocks blocks such as get pipette stats and start up pipette So what I'm gonna go ahead and do is Is I'm gonna define a function called start up pipette Cool and when I when I run this function, it's gonna print out Welcome to pipette Cool, and then all of my like stats over here. I'm just gonna move into a new function Two spaces there. Okay, and this is gonna be called Pipette stats awesome Cool and now the important thing about functions is you actually have to tell Python when you want to call them so down at the bottom I'm gonna say okay So when when this file runs it's gonna immediately know these are these variables and whatnot But and it'll know that these are functions, but it won't actually run the functions unless I tell them So I'm gonna be like start up pipette here and then the next line I'm gonna print out my pipette Stats and I don't have to actually print out those functions because in the function itself is the print statement So if I go ahead and do this as you can see ran just like before The thing is that this is just gonna be cleaner and nicer and as we add more cool functionality to our pipette We're gonna be really glad we put these into functions cool Whoops go back one Yes, okay So while loops this is like the most exciting part in my opinion guys So what we can do now is we can actually get user input and and to keep the program running as we like have a do new things so I'm gonna go ahead. Sorry. I'm gonna go ahead go ahead and Declare a new variable. It's gonna call be called terminate and Right now it's it's default as I'm setting it to false because I don't want it to start I don't want to you know close the program as soon as I as I start so I'm gonna say while While not terminate Which all this is saying is this is saying while Terminate is not true do some stuff. So let's first Let's print so just to make this like a little bit more. I don't know feeling like a tomagachi ish I'm printing out a line. You guys can do whatever you want though and Then the other really cool thing is there's this thing called raw input Which I honestly don't think you use too much once you move beyond a kind of beginner level that I could be totally wrong Actually, that's not true. But data scientists use it when they're doing stuff in their terminal Anyway user raw inputs really cool because it allows you to get user input so Over here. I'm the first thing I'm gonna do is I'm gonna say user input equals and no matter So whatever I put in here is just what shows up in my terminal, which you're gonna see in a second So now I want a way to quit which is kind of like the most important part So if the user input is equal to Quit Then I'm gonna set terminate To true Let's see if I forgot something. I think I think we're good. So I should be able to start the program and then quit So I run this cool. It started if I type quit awesome Looks like it's working and then if you want to be really fancy at the very end of like outside of this while loop We can be like print Goodbye Cool. So now that will print when we close the program So there's a couple other things I've got going on in here We're also gonna learn how to feed our pipette, which is really exciting if you you can you can take so what we're gonna do is we're gonna make So there's so we already learned about if statements But I'm gonna go ahead and explain how you can not only just check one condition But in an if statement you can actually check multiple conditions So go down here Dad else user input equals feed Wait, sorry guys live coding Okay, cool, let's look at I remember let's do let's do pipette stats first awesome because we already have that and a function so stats If you want to you know, call this function over here that has your pipette stats, we're gonna put in here We're gonna go Pipette stats. Cool. So all this is doing so all this is doing is when you run run through this while loop It's going to check that it's gonna get the user input and then it'll check that user input against these different For this if this if statement so Cool, and then we want one other thing We want to put an else statement here that Prints out if in case you type in a command that it doesn't understand. It's like sorry. There was an error Cool Okay, so now we should have the functionality of printing out the pipette stats when we type stats Cool, so I type out Okay, cool, right the stats are the exact same thing. I'm gonna take the stats out of the When you first get started so that it actually shows me different Cool, so then I type in stats and there we go. I got our stats about our pipettes awesome And there's one other cool thing we're gonna do so you know how we learned about a concatenation We are previously so we're gonna actually learn how to even feed our pipette, which is really really cool So if I go in here, so you got you can have as many LF statements as you want so user input equals Feed so what happens when something eats its weight goes up, so we're gonna do weight equals weights plus One and then we no longer want the pipette to be hungry. So this only says back to true cool So we're gonna say Hungry equals false awesome So let's quit this Now if we run this I'm not mistaken. We should be able to get the stats cool And now we should be able to feed the feed the pipe pipette and now when I get the stats again As you can see the Python has grown fatter Cool But yeah, so as you guys can see like there's this user input things really fun And there's a lot more than what I've just done now that you can do. Oh, we have to print a little nice Okay, so we're gonna print om nom nom So that there's some cool output there Okay cool looks good Lists, so this is really awesome If of course you want your pipette to like say random phrases because that would be amazing So up here at the top I'm gonna go ahead and make a new variable this variable. It's called a list and it will put some fun phrases So snake says I guess and I don't know how do you out? How would you spell out? Python is the best so obviously the snake is gonna say that because he's a python cool So yeah, so this is a list. It stores multiple values pretty useful and We're gonna do something really awesome. So Python has a standard library Which is just a set of modules aka for the if you're just a beginner You can just think of it as like code someone already wrote for you. So you don't have to so it's great They're all available by default. So at the top of my file, I'm just gonna go over here and put import random Cool and then the way you use specifically Oh, yeah, let me add so we're gonna add a little another remember how we added all these different user inputs We're gonna add one more and it's gonna be L if User input is equal to chat Cool, we're gonna print We're gonna we know we do we could print all the phrases, but that's not what we want We want to print just one phrase you could print the first phrase But that's also not that exciting because we want it to be random so This we just imported random which is from Python standard library and we're gonna go over here and we're gonna actually Pass in this array To this random dot choice, which is again something we since we imported the random here Python's gonna know what this means. So if the user input is chat Your pipette is going to say something So let's start over and see if we did that, right? So say chat. Oh So yeah, as you can see it's saying a random phrase of the ones that we added to this list up here Cool Okay, so we have we've added a lot of functionality But we can make it even better. So we're gonna we're gonna change our pipette into a dictionary So dictionaries have keys and values as you can see in my example over here now Instead of name being equal to fluffy. There's a dictionary called pie cat that has a name that is pointing to fluffy So the this is the syntax I'll be using for this it's just the the name of the dictionary and then little square brackets and then it's important that this is in a little quote Cool, so now we're gonna go ahead and modify our pipette data and change it into a dictionary Because this is gonna allow us to do even cooler things which will involve multiple pipettes in the near future Cool. So if you go over to your code At the top here. This is my Python Cool, so I'm gonna go ahead and do photo be that guy cool Name. Oh, yes. So that's probably Oh great catch. Just kidding. You didn't equal sign. Thank you. Yeah, I've got this really great Linter that tells me when stuff's wrong. Thank you so You will still you will still write in integers without quotes You will that that will not change even though you're writing all of these names in quotes because they're strings. Cool weight is 5.5 and hungry is so gonna be true and Booleans will still not have quotes. It's still the same Phrases cool and then you'll just use it just like that. It's the same deal Cool. So I'm gonna go ahead and delete these now that I have my My new Dictionary of my pipette and now there there will be something else will change So if I run this right now, I'm gonna get an error because no longer are let's see. Let's try some things. We get the error Yeah, so Like this name does it doesn't know to look that I'm talking about this name anymore So we're gonna change the syntax of this a little we're gonna be like, okay Go find this dictionary called Python and find its name Just like that Same with the other places where we use one of those variables my excellent snake case ha ha snake case Okay, cool, let's see if this works so if I want to chat Phrases is not defined. Okay Cool, let me see what ah, we didn't fix phrases. Yes, okay one more. Okay, awesome chat feed oh Sorry guys one more just kidding. I Wanted to like actually do this in front of you though because I feel like when people go through these things like quickly on their own It's easy for you guys to get like lost or not or like run into errors that I'm not thinking about So we will be having the same errors right now if you're following me falling along here Okay, okay, cool Feed awesome and quit all should be working cool. So that's a dictionary Next thing we're going to do is we are going to we're going to learn about function arguments So when you have a function you can pass in something some some parameters. These are called arguments So go ahead and if you want to create another pipette I think I'm going to create a cat again as per my other example Which I made to steal from he can be for he can be really fat Will not be hungry Okay, cool. So now I have my pie cat So so yeah, whenever you call one of these functions you will now pass in something called Pipettes, but initially we're going to just set we're going to just set pipette To one of these guys. So we won't be doing this dynamically just yet. So first. I'm going to set it to pipette Okay, so now when I call any of these functions That required to look at some of the data that the pipettes are using I'm going to put pipette there Um, stop. Okay, cool. We're going to wrap it up quickly guys. Don't worry In fact, if it's really that I might show you guys the even cooler thing and you guys can finish this part on your own Hold on one second okay, so You can follow this long online. It's pretty cool, but I want to get to Really fun bash commands. So you can actually make your pipette talk, which is super cool so if you add If you import OS which is operating system. Unfortunately, this only works for Mac right now guys. I know I'm sorry Import OS we're gonna do this really cool thing where you can actually use your computer and again My computer is not going to work right now. Unfortunately because of the way it's set up But when you start when you start your program, you can get it to say something silly like Welcome to pipette when actually when you actually run this function I don't know if anyone else is like that far and can try this out right now because I'm sad that my mind Won't actually be working But yeah, it's just like a really funny