Python Challenges: Predicting your age!

Transcript

English (Auto-generated)

Hello everybody. I hope everybody's doing really well. And today we're gonna be doing kind of a fun um testing out a fun formula for predicting our age. Okay so we're obviously I actually don't know who invented this formula but I've heard of it a lot. So we're gonna try it out with python of course and easing function and I'm not gonna read to you really quick um what it's about. Okay so basically um we have to take a list of ages when each of our grandparents died right? Um I put eight over here but I'm just gonna randomize them because I don't know um what my great grandparents died and then multiple number by itself and then all together take this for a root of the result and divided by two. Okay it's very um construction base and stuff but I just thought this would be a fun little problem for us to do. Um It's quite simple if you like because you don't need to know any advanced python things, you just need to well actually there is something that I'm gonna show you yesterday. But anyway I'm kind of going on a right. So yeah first we're gonna make a list um agents him and we're just gonna go ahead and copy and paste this into the list and here we're just gonna make it a list of course and the list and yeah okay we're a number want to go through each age. So I went for each grand age even though it's for each great grandparent stage in a list of ages. Okay and then what we're gonna go ahead and do is bearable here, squared age agents. Mhm squared age, grand age, times grand age there. Okay. And then we want to add them all together, Right? So we're gonna have all square aged in the air and we're gonna plus equals squared age. Okay? But the thing is um since we're not just signing it here, we're adding something to it, we need to define the variable prior to the loop. So all squared ages, we're just gonna make it equal to zero at the beginning. Okay. That's all we want to do inside the loop, outside of the loop, we're going to do is once they're all added together, want to get this square root of that. Okay. So what we're gonna do is we're actually I'm gonna teach you guys something. We're gonna use import math, which allows us to do a bunch of math things that we wouldn't otherwise be able to do with the operations that are given to us. So we're gonna do, for example, went to get the square root 1st. We're gonna have spur route squared pages. Okay? We have put squirt acres, just make it a little more readable. And what we're gonna do here is math dot squirt. Um So math, we're calling that we imported got square root, which is the thing that we're going to do something and then we're going to give it all squared Canadians to square it. That's what we want to square root right here and then what we're gonna do to that is just uh return square root ah squared ages. And just divide that by two. This is gonna give us some. Um Well I'll try in the second actually and then over here we put print um dict your age and here we're gonna have to define a bunch of ages. I'm just gonna put Predict age put 86 97 96, 53 67. Here I have five and I need A. R. And then I'm gonna put 85 and 69 and 73 and 70 Put 72. We have any 12345678. I have one extra in 72 and get rid of this one. Okay great. Now we can test it out and I'm gonna show you guys a little problem that you might bring into but I wouldn't do this problem. Just consider this more accurate. But you'll see in a second it's C. B. Into into predict age. I know um We're just gonna do, it's on three in the name of the file, like always predict your age. Popeye that's right. 112.33 is something. And this is the problem that you might run into if you consider this a problem when predicting your age. Okay so what we're gonna do here is just this is um something called doing just normal division right? It gives us the divided thing. But there's something called floor division which we can do with using double slash. Is that a double division operator? Is that? It's just gonna kind of cut off the decimal part. And this right here is float everyone an integer then this is how you would get it with when dividing something if you want an integer not afloat, um you just do that actually and I'm just gonna show you guys something really quick. I didn't do that with this terminal. Okay. Really quick. I'm just gonna explain something that um let's have another duh. Yeah, now that's gonna give it no. Right. And what we do is return numb Divided by two. Okay. And we're gonna get it print division And I'm gonna get a number that's divisible by two. Let's get it for its tribute to. Right so that so what's the difference between a flow and an enter? If it's just going to be equal to two, you'll see in a moment. So we're gonna do C. D. Once again into predict into perfect age and then we're going to prove that and uh okay I see what's going on. Okay I'm gonna put this in a different file really quick story that doesn't but I just want to kind of show you guys I'm doing this plus division. It's fine that's there. Okay. And I'm gonna go ahead and place the division I And it gives us 2.0. That's still blow this little part right here after the dot and the diet. So that is still afloat. So even if it is divisible by the number and there's no crazy decimal after it, it's still float because we get 2.0. So if you were born in the future we just put double um division symbol only get a normal. Okay, so in this case if we put double christian symbol, okay, we're going to get an in teacher and no, let's hear. Oh yeah, okay, so bye, yep, that's this is how that works. Um And yeah, as you can see it's kind of getting rid of the decimal part of it. Okay, we were to take that problem once again Crazy. There's some over here and here, it doesn't so thank you very much for joining this podcast. I think this was a very decent um mhm yeah, this is a very decent problem. I got to show you guys that's where it's an import math. You can use a bunch of different math operations with this. They can do with normal operators but but yeah, I don't know much of them haven't used many of them, but there was kind of a basic one that you can't do with normal operatives, hence why I know that important. So yeah, thank you guys so much for joining this podcast and I will talk to you guys
57 Views 0 Likes 0 Comments

In this codecast we will be implementing a formula that supposedly can predict your age! Let's try it out :)

Comment
Leave a comment (supports markdown format)