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

3x/sqrt 4x+5 rationalize the denominator
You save $10 on gas every week because you take the bus to school. you have class 5 days a week. what is your average benefit per day of taking the bus to schoo
Which force is responsible for these orbiting motions?
how to use renewable energy
Find the derivative of f(x) = -5/x at x = 11.
Which particles make up the nucleus of an atom?
The nucleus is surrounded by a semipermeable membrane. What would happen if this layer were permeable to most substances?
If it were possible for a rocket to travel at the speed of light (3.0x10 m/s about how long would it take to reach the speed from the rest
A line passes through point (-2, 5) and has a slope of . Points A(x, 3) and B(-2, y) lie on the line. The value of x is _____ , and the value of y is _____.
Who is referred to as the father of microbiology?