0
I have the following code:
# -*- coding: utf-8 -*-
def soma(lista):
soma_num = 0
while soma_num <= lista:
soma_num += a
return soma()
a = [1, 2, 3, 4]
print(soma(a))
I know it will give error on line 7 and 10, saying it is not possible to use the operator += in list and integer. But my question is the next one, in this code that I have built only and possible to solve using the for loop or it is possible using the while loop. Or I would have to add a for in while. For I have an example and it works perfectly with for loop.
Rubico that my doubt even, in the loop for I could quietly. I was having trouble in the same while.
– GlaucioFonseca
was missing a Return there, but I think I got the idea. I’ll arrange ;)
– Rubico
I got the idea yes, it was worth it.
– GlaucioFonseca