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

¿Dónde hay servicios religiosos (religious services) en español? (3 points)
Which is more mountainous, eastern or western north america?
Which Invaders of the Roman Empire came from the farthest Eastern Point
Given that the solution set to a system of three linear equations is a line, which of the following is true about the system? a) The system can be either incons
How long does Robinson Crusoe say he lived in fear after seeing the footprint in the sand?
Summary about how the Moon moves around Earth.
The scale for a scale drawing is 8 millimeters: 1 centimeter. Which is larger,the actual object or the scale drawing? PLEASE PLEASE PLEASE EXPLAIN!!!
a coffee pot holds 5 1/2 quartz of coffee. How much is his in cups?
In the lagoon by Joseph Conrad what does the white man offer to do for Ariat after diamelen dies
Which molecule is active during the last step of dna replication