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

At Jones College, there are a total of 100 students. If 30 of the students have cars on campus, and 50 have bicycles, and 20 have both cars and bicycles, then h
An infant is 32.625 inches (in) long. Write this as a common fraction.
At Jones College, there are a total of 100 students. If 30 of the students have cars on campus, and 50 have bicycles, and 20 have both cars and bicycles, then h
What is the HCF of 2 x y and 6 x y?
What are some behavioral adaptations for a porcupines?
could you tell me what is an embryo?
What does "to see the elephant mean"?
why are fossils of clams more numerous than those if the worms or cnidarians ?
What Is the Connection Between Sulfuric Acid and Hydrochloric Acid?
Baker university hired its first coachj in?