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

When measuring weight 6 small dogs are approximately equal to 9 large cats. How many large cats are equal to 54 small dogs? How many small dogs are equal to 12
Which entrepreneur created a benevolent company town for his employees? a. Henry Ford b. Henry Frick c. Milton Hershey d. Atwater Kent
Which of the following seas does not surround Greece? a. Adriatic Sea c. Mediterranean Sea b. Ionian Sea d. Aegean Sea
Que guerra peleo los Estados Unidos en los años 1900
Which metric prefix means “a million”? Kilo Tera Giga Mega
Which one of the following words means the surgical repair of the larynx.a-laryngostomy b-laryngoplasty c-laryngostenosis d-laryngectomy
What tribe did queen Nizingha belong to
How weight can you lose by riding a bike for 5 hours a week
Which of the following could be a master status for someone? All of the above An occupation An AIDS diagnosis A physical disability
Which organ system is responsible for transporting oxygen throughout the human body? A. digestive system B. respiratory system C. circulatory system D. excretor