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

True or false mononucleosis is caused by bacteria
Let W be an acute angle. Use a calculator to approximate the measure of W to the nearest tenth of a degree. cosW=0.54
When does behavioral isolation occur?
10. In "The Necklace," which of the following literary elements is prominent in the story's ending? O flashback O irony O metaphor O point of view
Which sentence is true about the two settings used in Bram Stoker’s Dracula? A. England represents rationality, and Transylvania represents superstition. B. Eng
Briefly explain the effect of global warming?​
An intentionally disruptive program that spreads either from program-to-program or from disk-to-disk is known as a(n)
What is the most common element in the universe and how does this give evidence for the Big Bang theory?
Clint is interested in making an offer on a house with hardwood floors that will need to be replaced. The hallway is 18 feet by 6 feet. The kitchen is 20 feet b
Humans rely on minerals for many daily uses. How could the distribution of mineral resources be affected as the human population continues to increase?