1
I have one question: I’m trying to solve an exercise for learning, which is the following:
inform a list. Ex: [1, 3, 5, 1, -10]
, and return the average between the number and the next number. In this example, you should return: [2, 4, 3, -4.5]
.
I have no idea how to "slice" a list, because it has no limit, could create a list with 100 values...
Pow, show me a show! I was trying to do a little different, because since I’m a beginner, I don’t understand very well, so I was always trying to get the Indice[0] and the Indice[1], average the 2, and then remove the Indice[0], moving your place to the next number, would it work?
– Guilherme Jacobus
And another, why did you use pos < size-1? This -1 is doing exactly what?
– Guilherme Jacobus
It works yes, I added a second version with this approach.
– Evilmaax
The
pos < tamanho - 1
is the control of your list. As you need 2 elements to have the average pos will increase with each loop: it starts with 0, then 1, 2.... The noosewhile
it ceases to be executed when pos is larger than the total size of the list -1, that is, if the list has 10 items it will execute up to pos = 9, so that it does not arrive at loop 10 and has no one to average and ends up generating an error (position 11 of the list does not exist).– Evilmaax
Ah, got it, Max! Man, thank you so much for clearing up my doubts! I’m entering this world of programming, next year I start college, and I want to get ready now, you helped me understand something very show. Thank you!
– Guilherme Jacobus
Show man, don’t give up and study hard. And the best way to learn is teaching. So if I helped you and you were grateful, help someone when you have the chance. That is why the community exists =) Ahhh, and if you can vote in favour of my answer I would also be happy. Hugs
– Evilmaax
I will help yes. I am trying to find where to vote in your reply hahaha
– Guilherme Jacobus
Up there, where you’ve marked the approved response, there’s a little fledgling up and down. Click the button up whenever any answers are helpful and help you solve a problem.
– Evilmaax
All right, like Max!
– Guilherme Jacobus
It would be nice if you took a tour of the https://answall.com/tour. And a final tip: Study with the Guanabara language course on Youtube, you’ll evolve a lot, from basic to intermediate
– Evilmaax
I don’t have a 15, apparently you haven’t counted my vote in your question yet, but as soon as I get to 15, I come back here and leave the vote! Okay, I’m gonna take this tour, and watch the Guanabara course, thanks for the tips.
– Guilherme Jacobus
Show. Abração e bons estudos https://www.youtube.com/playlist?list=PLHz_AreHm4dlKP6QQCekuIPky1CiwmdI6
– Evilmaax