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

solve the equation 4x + 6 = 4 + 2(2x + 1). Which choice describes the meaning of his result, 6 = 6?
Find the midpoint between P(-8, -7) and K(11,5).
3. A trail mix recipe includes granola, oats, and almonds. There are 135 Calories in a _ cup serving of the trail mix. How many Calories are in 2 cups of trail
A bicycle has a mass of 39.5kg on Earth . What would its weight be on moon (g=1.6m/s^2)
What type of cells make up all parts of the human body? Select one: Archaea cells Circular cells Prokaryotic cells Eukaryotic cells ____________________________
find the equation of the line use exact numbers
Which colony provided the basis for the declarations and resolves?.
PLS HELP ASAP THANKS ILL GIVE BRAINLKEST PLS THANKS PLS ASAP PLS PLS
A ladder leaning against a wall is used to reach a window that is 16 feet above the ground. The wall is 12 feet from the bottom of the ladder? How long is the l
PLS HELP ASAP THANKS ILL GIVE BRAINLKEST PLS THANKS PLS ASAP PLS PLS