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

Which type of lines match these equations (2/3)x =(5/3)y 2x-5y=0
What was one root cause for slavery?
a .35 m solution of weak acid, HX, has a h+ of 4.15×10^-3. what is the value of ka for this acid
Where should a person who wants to work as a teacher aide in a Roman Catholic school begin to look for the job? A. Bishop B. Principal C. Diocesan Office of Ed
Point O is the center of the circle in the diagram. What is m∠BCA ? A80° B75° C70° D65°
how much did briana save by purchasing a backpack that cost $45 with a sales promotion of 20% off instead of a backpack that cost $42 with a sales promotion of
How did the mining industry affect future industries in the Indian Territory?
Which continent is Italy in
Which sentence is punctuated correctly? A. Janice replied, "yes, I've had several." B. "Have you ever had a wart?" asked Billy. C. "Toads do have bumps on the
X^2+2x in factored form