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

Can anyone help me with this
what type of seismic wave shakes particles at right angles to their direction of travel?
what is qualitative and quantitive data?
what is 72:75 as as fraction
Is the word "closely" an adverb or adjective
what are three characteristics of the alveoli promote gas exchange?
How does the atmosphere balance the unequal heating of Earth's surface
Any potentially harmful substance that humans add to an ecosystem A) is called pollution. B) might cause acid rain. C) is always a carcinogen. Eliminate D) h
what type of seismic wave shakes particles at right angles to their direction of travel?
Which of the following is a factor that contributed to the formation of the Farmers' Alliance? low crop prices restrictive tariffs government regulations lack o