Tamannagaur20 Tamannagaur20
  • 01-11-2021
  • Computers and Technology
contestada

Can someone help me write a code in python to find the sum of all the odd numbers from 1-301.
In which python makes a list of all the odd numbers and uses a loop

Respuesta :

arinaaznaureni
arinaaznaureni arinaaznaureni
  • 01-11-2021

arr = []  #an empty array

for i in range(302):  

   arr.append(i) if i%2 != 0 else None #add a new element, if its odd, else - nothing

print(sum(arr)) #printing the sum of elements

Answer Link

Otras preguntas

What do all electromagnetic waves have in common? They have the same amplitude. They have the same frequency. They have the same wavelength. They have the same
What means variety and refers to the racial, ethnic, cultural, and other differences among people? Select one: a. Diversity b. Diffusion c. Desperation d. D
The measure of an angle is 4y. Find the measure of its complement
which Union general impressed President Abraham Lincoln with his tenacity by stating the following? "find out where your enemy is. get at him as soon as you can
how does an earthquake cause a tsunami?
how can a heterogeneous mixture be recognized
someone please help me
What did Germany do to Rhineland? And why?
¿Qué obras de arte o de literatura influyen en tu vida?
What were Ortoghs? a. Mongol provinces b. Chinese coins c. associations of caravan merchants d. Mongol boats