Python Challenges: Same case or no?

Transcript

English (Auto-generated)

So like I said this week we're very much going to be focusing on types and manipulating types of military and all that fun stuff. Um So today we have once again a very basic challenge um where we have to we're going to be given two strings which are going to contain one character And we have to check one if it contains a letter or a number or a special character and then if it contains a letter, if both will contain the letter R. This in case or not and must be at least the way we're going to output this is if one of the um character Celestine isn't a letter return negative one And if it if both of them are the same case we took one and if they aren't the same case return zero. But um so I hope I explained that for example, what would this would this be That should return one this should return zero and this should return -1. Okay, so I hope I explained myself um pretty well, I'm not sure. So this is basically gonna be pure statements what I'm gonna do right now and there are clearly better ways to solve this. So I want you to take the positive video or after this video um and tried to solve it without using just pure if statements like try to find a creative way to do it. I guess you can say maybe use loops somehow, I don't know but actually would use but just try to be creative about. Okay. Really? So the first thing I do is if and we're going to use a lot of think of it for example is proper. It's basically just checks if it is an upper piece letter or a lower case letter. Um, this is either gonna equal true or false and be done. Is it data is upper return on. Okay. Um, actually is come on. Perfect. Now we're gonna do Alice A duck is lower equals true and b dot is lower equals oh dang it disease equals true return. Oh my God. It's going so often return one another LF statement. El is a that is as if it's part of the alphabet we called false or because if either of either of them are not part of the off of it, then we're gonna return negative one. It doesn't matter both of them are, but at least one we're going to do it. That's why we're using or instead of. And a lot of that clear be the yes house. Yeah. We called frogs. Mm hmm. Return negative one. Oops. As in the only other option in this scenario is for them not to be the same case, but both the letters. So that's where we're just doing else. Return zero. Okay. And that should work perfectly. Now we're gonna test it first and then I'm gonna tell you guys something that is not being done. The most efficient way. None of this is super, super efficient. That's why I'm trying to do it in a way where you guys can clearly re factor and clean this up. But first let's try it out before I tell you guys the most obvious thing and the little things that I'm gonna give you guys the first test it out, print same english or not and then let's give it a and lower case. Big. Okay, so now we're gonna do is Yeah. Oh damn it. We need to there you go. Same taste the pie away from python three, same chase that cry do string object has no attribute is out sitting is alpha. Yes. Actually I didn't mean that. Thank you for telling me. Okay. Okay. Zero. Okay, so it works perfectly. Let's try with every single scenario just to make sure it works. Start making them both upper caves like that. Okay. And your returns one. Let's make them both lower case, It returns one. Now let's make one a special character -1. And as you can see it works perfectly. Now the small hint I'm gonna give you guys before you guys try to re factor yourselves is that it's not necessary at all to have that equals true there. Why? Because this is either gonna equal true where it's going to return that or it's gonna equal false. It's just gonna skip over it. So there's no need to have that equals true. This is either this is a boolean, just keep that in your head. So this is either gonna be false or true and if it's true it does when it returns this and it's not that it's just gonna pass over. I hope I explained myself correctly, but it's actually pretty supportive just there is not necessary to include that and we can still check if it works and it works very quickly, so let's try it when we would actually need to use that. Okay. Mhm. And blue one. Okay, so as you can see that's how this would work. And thank you so much for tuning you guys. Thank you for watching this and please please remember to try and re fractures yourselves, clean it up whatever you need to do and try to come up with a super creative solution for this, because this can be pretty like, as you can see in this coding challenge, I solved the in a very repetitive way. So I want to see if you guys can do it, clean it up and not make it seems repetitive. That makes sense. So, thank you guys so much for watching and I'll see you guys from the next one.
42 Views 0 Likes 0 Comments

Pretty basic and simple, we're given two strings and we have to check if one, the string contains a letter or a special character (or number), and two,...

Comment
Leave a comment (supports markdown format)