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

Factor completely 3x2 + x + 7.
DUE TODAY PLS HELP ASAP.. travel is faster as density of matter increases a. mechanical waves b. electromagnetic waves
what value of m is not a solution for the following inequality 3m ≤ 36​a.m=4b.m=9c.m=12d.m=15
twice a number plus 5 equals 81
Are all relational numbers real numbers?
Find the slope and the y-intercept of the equation 4x + 5y = -9
The recipe for Jack's Famous Chili uses 222 teaspoons (\text{t})(t)left parenthesis, t, right parenthesis of red hot chili powder for each cup (\text{c})(c)left
how did the robertsons get fresh drinking water?​
Help me with this question please !! *if your in family and community service, help me with these questions please*
One of the harmonics of a column of air in a tube that is open at one end and closed at the other has a frequency of 448 Hz, and the next higher harmonic has a