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 is a major difference between the poetry of emily dickinson and the poetry of walt whitman?
x cubed divided by x squared
which is a type of functional document? a. research paper b. driver's license application c. text message d. doctor's note
P(x)=x^4+32x^2+256 Find the zeros and also factor completely
what is the solution to the system of equations? y = x – 10 2x y = 4
industrial production in china declined during _____. the great leap forward the may fourth intellectual movement the 1911 revolution the chinese war for indepe
An insurance agent says the standard deviation of the total hospital charges for patients involved in a crash in which the vehicle struck a construction barrica
A scatter plot is made with the data shown: Number of People Mowing a Golf Course 2 3 4 5 6 7 8 9 10 Time Taken to Mow the Golf Course (hours) 16 13 10 8 7 6 4
what percent of an object's earth weight is its weight on mars and oon the moon
Evaluate the expression for the given value of the variable(s). 5a + 5b; a = -6, b = -5 a. -55 b. 55 c. 5 d. -5