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

Find the center and radius for the circle, given the equation: x^2-14x+y^2+8=16
11. After an hour on the expressway, your passengers need to use the restroom and they want to get some food. As you approach the next exit, what color sign wil
Which compound is a metabolic intermediate of the light-independent reactions in photosynthesis?
A large arc of fertile farmland
Explain two ways in which the lens is structurally suited to perfrom its function
Solve |4x – 5| = 9. Show each step of your work.
All the constitutional convention, delegates from the northern and southern states disagreed about
what is the result of isolating x^2 in the equation below? x^2+(y-5)^2=30
How is a system of equations created when each linear function is given as a set of two ordered pairs?
The increasing price of land in the United States has resulted in an increase in the __________. A. number of small farms B. size of small farms C. number of la