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

How is Franz different from the other boys in Swiss Family Robinson
what would you do if you were a warewolf?this Is my homework so plz help me asap (as soon as possible)
Which of the following was NOT a reason for United States to look beyond its boundaries in the late nineteenth century? a. to sell surplus goods and procure raw
1.) Properties of a compound are_____the properties of the elements that make them up. 2.)Compounds form as a result of a______
What is carbon fixation, and how does it relate to photosynthesis?
How did Ming China's relationship with Japan differ from its relationship with Vietnam? A. Vietnam was outside the sphere of Chinese influence, while Japan was
What number is between 1 and 20 with factor of 5
Archaea and eubacteria are primarily different in _____.
__________ is the point of view that makes the reader feel like a close friend or confidant. Limited omniscient First person Objective Omniscient
_____ established plantations on islands off the coast of Africa.