Learn Python Programming - 28 - Find the Bigger Guy (Exercise)

Hello There: Exploring the "Bigger Guy" Problem

Hello there, beautiful friends! Welcome back to my channel, Clever Programmer Calm. Today, we're going to tackle a pretty cool problem that's all about finding the bigger guy between two numbers or strings. The problem is straightforward: if you give me two inputs, I need to return the one that's greater.

To start, let's define our function. We're going to call it "bigger guy." This name speaks for itself - we want to find out who's the bigger guy between the two inputs. So, what are we taking in? Our function takes in two numbers or strings. Yes, you read that right - Python knows how to check strings against each other, so we don't need to do anything special.

Now that we have our function defined, let's talk about how it works. We want to compare the two inputs and return the one that's greater. But what if they're equal? Well, in that case, we don't care which one we return - we just want to return either of them. To specify this for you guys, I'll add another test: 10 10 should return 10, regardless of which one is greater.

Let's break it down further. If num1 is greater than num2, we return num1. If num1 is not greater, we return num2. In the case where num2 is equal to num1, we don't need a condition - we can just say else and be done with it. This is why we don't need to give a specific condition for this problem.

Now that we have our logic down, let's test it out! We'll start with 3 and 5. Our function should return 5 because 5 is greater than 3. Then, let's try 5 and 9. Again, our function should return 9 because 9 is greater than 5. What about the case where we give in 5 and 5? In this case, our function should also return 5 - we don't care which one is greater.

Before we proceed, let's take a moment to talk about how our code works. We're using if statements and comparison operators to compare the two inputs and determine who's the bigger guy. It's simple yet effective! If you haven't tried this problem before or need help solving it, please don't watch this video - try the problem on your own first. But if you do want to see how our code works in action, we'll run some tests using assert statements and see if our function passes all of them.

When we run our test cases, our function should pass all of them because we've covered every possible scenario. And that's it! We've solved the "bigger guy" problem. If you're ready for the next challenge, I'll be discussing it in my next video. Don't forget to subscribe and hit the notification bell so you don't miss out on any future videos.

Thanks for watching, everyone!

"WEBVTTKind: captionsLanguage: enhello there are my beautiful friends in this video I want to talk about who's the bigger guy this is Kazi from clever programmer calm and we're going to solve a pretty sick problem sick as in good now this problem essentially wants you to find max of two numbers so if I give you look at it look at line 19 if I give you one two you should return to if you give this function bigger guy function if you give it 10 and 20 it should return 20 if you give it 20 and 10 it should return 20 and if you give it 2 and 1 it should return to get the idea and same thing with the strings but you don't have to do anything special Python knows how to check strings against each other okay so let's code this up notes or below solution is below I think you guys know the drill at this point if you're watching this on YouTube that is if you're watching it on my website everything is going to be there in your face so first step d/f define we're writing a function that does this right look at the instructions write a function bigger guy so I know that I do this with my eyes closed now what is it taking it takes in two numbers so I know that it takes in two inputs I can say num1 num2 or something okay and what can I do here well I want to check between those two numbers in whichever is the bigger one I want to return that number right so using if statements and comparison operators we can do all of this together if you haven't solved this yet or if you haven't tried to solve it on your own please don't watch this pause try the problem then come back but here's a solution for you guys for you eager beaver's if num 1 is greater than num to return num 1 right if num 1 is bigger well otherwise return num - right in the case where num 2 is equal to num 1 do we care which one we want to return of course not we don't care we just want to return any of them it doesn't matter okay to specify that for you guys here I'll be nice and I'll add in another test ok 10 10 it should return 10 I really don't care what it returns in the case where there two are the same okay and what if they are what if num 2 is the one that's greater well in either of those cases right the first case we return num 1 if it's the case where they're equal or if num 2 is greater we return num2 which is why we don't need to give a condition we just say else and we're done now let's let's check this bad boy and let's see how it works right let's let's give it some ok here I'll just do it to be extra tangible here for you guys right so let's let's do 3 5 it returns 5 let's give it 5 9 it returns 9 and if I gave it 5/5 it should return 5 right so we know what it does and here let's uncomment this line and when I run it it should say your code is correct which means that it passed all of these assertion tests and then at the end it said your code it then it went and said your code is correct now what if all right I'm going to save that for the next problem because next problem is going to be a lot more fun and more challenging where you're going to have to solve the biggest guys so if I give you 3 guys what do you do we're going to discuss that in the next problem if you haven't already subscribe I'll see you in the next videohello there are my beautiful friends in this video I want to talk about who's the bigger guy this is Kazi from clever programmer calm and we're going to solve a pretty sick problem sick as in good now this problem essentially wants you to find max of two numbers so if I give you look at it look at line 19 if I give you one two you should return to if you give this function bigger guy function if you give it 10 and 20 it should return 20 if you give it 20 and 10 it should return 20 and if you give it 2 and 1 it should return to get the idea and same thing with the strings but you don't have to do anything special Python knows how to check strings against each other okay so let's code this up notes or below solution is below I think you guys know the drill at this point if you're watching this on YouTube that is if you're watching it on my website everything is going to be there in your face so first step d/f define we're writing a function that does this right look at the instructions write a function bigger guy so I know that I do this with my eyes closed now what is it taking it takes in two numbers so I know that it takes in two inputs I can say num1 num2 or something okay and what can I do here well I want to check between those two numbers in whichever is the bigger one I want to return that number right so using if statements and comparison operators we can do all of this together if you haven't solved this yet or if you haven't tried to solve it on your own please don't watch this pause try the problem then come back but here's a solution for you guys for you eager beaver's if num 1 is greater than num to return num 1 right if num 1 is bigger well otherwise return num - right in the case where num 2 is equal to num 1 do we care which one we want to return of course not we don't care we just want to return any of them it doesn't matter okay to specify that for you guys here I'll be nice and I'll add in another test ok 10 10 it should return 10 I really don't care what it returns in the case where there two are the same okay and what if they are what if num 2 is the one that's greater well in either of those cases right the first case we return num 1 if it's the case where they're equal or if num 2 is greater we return num2 which is why we don't need to give a condition we just say else and we're done now let's let's check this bad boy and let's see how it works right let's let's give it some ok here I'll just do it to be extra tangible here for you guys right so let's let's do 3 5 it returns 5 let's give it 5 9 it returns 9 and if I gave it 5/5 it should return 5 right so we know what it does and here let's uncomment this line and when I run it it should say your code is correct which means that it passed all of these assertion tests and then at the end it said your code it then it went and said your code is correct now what if all right I'm going to save that for the next problem because next problem is going to be a lot more fun and more challenging where you're going to have to solve the biggest guys so if I give you 3 guys what do you do we're going to discuss that in the next problem if you haven't already subscribe I'll see you in the next video\n"