1
k=5
for k in range (5,10):
print(2*k**2)
50
72
98
128
162
I need to add these results.
1
k=5
for k in range (5,10):
print(2*k**2)
50
72
98
128
162
I need to add these results.
3
Using list comprehension, would be:
soma = sum(2*k**2 for k in range(5, 10))
Read: for each value of k
in the interval range(5, 10)
calculate 2*k**2
and add up all the results.
You can read more about list comprehension here.
0
You can do it like this:
soma = 0
for k in range (5,10):
soma += 2 * k ** 2
print(2 * k ** 2)
print(soma)
thank you very much !!
Browser other questions tagged python
You are not signed in. Login or sign up in order to post.
many thanks friend for the lists!!
– Rafael Uemura
List comprehension, right? No compression.
– Leonel Sanches da Silva