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

How does the oxygen in the atmosphere help protect and support life on Earth?
Photovoltaic cells a.work because solar energy striking their surface is converted directly to electrical current. b. causes an uneven magnetic charge to dev
A sample of iron receives 50.J of heat energy that raises the temperature of the iron 25.0°C. If iron has a specific heat of 100 J/kg°C, what is the mass of the
How would you say "I tested negative" in Spanish (referring to a medical test)?
if a cage can hold 8 chickens, how many cages will be needed to hold 300 chickens
what importance do fossils have to scientists
Interquartile range of 40,25,15,22,50,30
When 4 times the number X is added to 12, the result is 8. What number results when two x x is added to 7?
3 1/2 - 2/5 Please answer fast and if you can explain. Have a Great Day! :)
What type of disease transmission is most likely represented by the graph shown belon infected L A person to person B Focorre C Area D Ferrame sro a route