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

50 POINTS! Plot function h on the graph. NO LINKS
why is good governance necessary​
Which detail best supports a message about extracurricular activities? Anson Does It All by Marty Tarvin
Which is the greatest fraction in this list? 1/2,3/4,5/8,11/16
If a teen buys a customizable cell phone face plate to avoid being rejected by peers, this is an example of?
If a radioactive decay produced 2. 05 × 1011 j of energy, how much mass was lost in the reaction?
Quick algebra 1 question for 10 points! Only answer if you know the answer, quick shout-out to tariqareesha2 and MrBrainly, tysm for the help!
______ in 1958 coined the term victim precipitation, which simply means that victims sometimes start the conflict that ends in their own death.
Review erikson's industry versus inferiority stage. how does self-esteem change during middle childhood? what contributes to these changes?
What is the identity of a metal that has a mass of 27.0 g and a volume of 10.0 cm3? Group of answer choices A. Gold B. Aluminum C. Lead D. Copper