Python Challenges: Sum of Negatives and Count of Positives

Python
Transcript

English (Auto-generated)

Yeah. So um first of all, I just want to apologize for my voice really quick. I have been feeling a little bit sick clearly, but that does not stop us. I'm sorry from doing our code challenges. So um so the toy problem or co challenge I guess you could say that we're going to do today is some of negatives count of positives. It is pretty self explanatory. Um And yeah, we're just gonna get right ahead to it. Um So what we're gonna do first is have variable where we can put our kind of positives or some of the negatives, et cetera. And also I wanted to mention that if we are given an empty list that we're just gonna return an empty list facilities of what we would do in that scenario. So we're kind of positive. We're just going zero for now. Some meg's equal zero. Some names equal zero. And we're going to make a list called list. We're just gonna make it an empty list for now, where we're gonna be putting all our that we're gonna be inputting Arkham positive later. So the first thing we wanna do is check yes it is if the current element we're on is a positive or a negative number. So we're gonna do is four element. Like I said in python we could use X. Or any name for this but we're just gonna use element because the python tried to have really readable code four element in l we're going to check if what are we going to check if it is positive or negative. So we're going to check if it's positive. Yes. A late is greater than zero. That would mean positive. Actually just making Not equal to zero. We are going to add one to our variable count pods. Yeah. Plus one right there. And we're gonna make a list of people. Mhm tone pods and some. Right, okay. And now over here we're gonna do Alice and we're right. Now what we're gonna do is check if it's an empty list list. Yeah. If L close this an empty list, we are going to return an empty list. So there we go. Okay. Okay. Okay. Actually, this should all be indented. Further talk about that. Okay. We're going to do else girls. We're going to do, Oh wait, sorry. I'm gonna take that out here. I forgot how. Next in L A forks for a moment. That was really weird. Okay. I live list closely equals. But then we're going to return, I apologize for the smaller fusion. Okay. Now else if it's negative. Okay. So else if it's not positive and it's not an empty list and it has to be a negative number. So we're gonna do is add one class, one class equals one to someone some next. And then list equal count of pods and some next. Okay, perfect. And that should work. So let's test it out right now. Outside of the approach, man, I really apologize guys. Okay. Print and then we're gonna put the name of the function. Some legs legs turned pots. And now let's say we're going to make the list equal to mm hmm. Let's say 123456. Oh wait 1 2 -4, negative two three and negative. So. Okay. Let's make it really random right there. Okay. And now what we're gonna do is quite three right here in the terminal. And let's say the new house um leg count, pause dot pi None. It says none. Mm hmm. Let's see what's going on here. Okay, so let's go through our code really quick. We're gonna teach you guys how to like debug. I guess you could say. So here our current uh current number, income pauses, zero current value of some next zero. Current value of list with an empty list. So for every element. L As in 1st Reading of one, it's element Is greater than or equal to zero. Then we're gonna add 1 to kill pots. And then this is gonna be going counter pause. And sometimes, right, okay. Now l if list because um an empty list, we're gonna return an empty list. And oh, I apologize so much guys. And then return list. Okay. You see how it's very confusing at times. But as you can see as we were debugging, I realized that we had we were turning an empty list here. But when it was when we were at it positive, where we were adding the negative, then we were returning anything. Okay, so kind of like a little debugging process that they have you guys that plan? Okay, now 3, 3. There are in fact three. Um there are in fact three, there was a negative score plus negative tool State of six. Well the sum is wrong. Oh plus equals element I have very sick right now guys, you guys can anything? Okay element Okay now it should work but you guys can kind of see the process now, it does work and everything works perfectly. I apologize for a voice, I apologize for some of the confusion shins we had but I think at least you guys got to see what kind of thinking process when debugging and stuff like that and um it's a very good process when debugging to read through all of your code. May have a piece of paper in hand and put the value of some of the variables, one returns of the variables you have and how it changes throughout your code and then it's kind of easy to deeper than I guess you could say. All right, even as you're reading it, you can tell like if maybe it's a syntax error, maybe you're returning something like in this case, you know, So that's always good. Okay, so for this coding challenge there is obviously a ton of improvement in my code but I want to see if you prize have any ideas on how to re factory um or in other words, how to clean it up a little bit, like, or how would you guys do it? I encourage you guys to send me your results in your solutions and yeah, thank you so much for coming here and tune in on the next one.
150 Views 0 Likes 0 Comments

In this CodeCast we're going to be given a list of numbers and we have to return the sum of the negatives and the count of positives, pretty self expla...

Comment
Leave a comment (supports markdown format)