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

F(x)=4x2-6x+2 and g(x)=2x2+4x
Why did Hebrew/Jewish teachings heavily influence Christianity?a. Jesus traveled around and took ideas he encounteredb. Jesus was raised following the Jewish fa
What is considered by the federal government to be what your family will be able to pay per year toward your school expenses?
Brianna’s home state was holding a singing competition, and the prize was a recording contract. brianna loves to sing, but she gets anxious when she sings for s
Which of the following statements best describe why the mucous membrane on the inner lining of the esophagus is considered a tissue? Choose 2 answers: The epith
Scientists have been studying the size of three populations in a grassland. In this ecosystem, hawks (a type of large bird) eat sparrows (a type of small bird),
Please Help Me..........................
A car starts from an initial velocity of 10m/s and accelerates at 2.5m/s².how long will it take the car to reach a speed of 40m/s.. How far doea the car travel
realmente ayudenme p ahhhhh
HELP PLEASE ANYONE>>>>>