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

To win a trivia game, Nevan must score 90 points. Each correct answer is worth 134 points, and each incorrect answer is worth −14 points. If he gets 58 question
x+13=-15 Help!!!!!!!!!!!!!!
Please help me with this . I don't understand it
Which of the following is correct regarding the strategies of each side during the Civil War?
What antibiotics are most effective against MRSalA?
the viruses are organisms Prokaryotes Eukaryotes Unicellular Cellular
The area of a rectangle is 215.2 m2. If the length is 16 m, what is the perimeter of the rectangle
Taylor used the everyday image of a spinning wheel as a metaphor to describe how God transformed his life. What image or images do you think you could use to de
What is a Archipelago?
Which of the following describes how the natural resources found in North America Countries affect their economies?