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 the difference between fraternal twins and identical twins
What aspect of industrial revolution undermined mercantilism
i need help im confuse
how did Andrew Carnegie use vertical integration to increase his power?
Which is a compound machine?
Why did the Romans give up some of there land after they already had a lot of land
When slicing a cube perpendicular to its base, parallel to its base, or diagonal to its base, what is the maximum number of sides the cross section shape could
should schools serve chocolate milk ? write 2 pheragraphs
How to solve it? I need help
Adult tickets to a basketball game cost $5. Student tickets cost $1. A total of $3,250 was collected on the sale of 1,266 tickets. How many of each type of tick