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

5 • x = 115. What is the value of x? (Five times X equals/is 115.)
In this excerpt, the author persuade readers to believ includes facts expresses opinions addresses hopes describes details
Jilk Inc.'s contribution margin ratio is 61% and its fixed monthly expenses are $47,500. Assuming that the fixed monthly expenses do not change, what is the bes
High rates of inflation often result in people spending inordinate amounts of time trying to make transactions and finding ways to keep the real value of their
Refractometry is an analytical method based on the difference between the speed of light as it travels through a substance (v) and its speed in a vacuum (c). In
All brake lights are dimmer than normal. Technician A says that bad bulbs could be the cause. Technician B says that high resistance in the brake switch could b
robin wants to find the area of the triangle below. to find the area of a triangle, multiple the base times the height and then divide by 2. the base and height
what is the moons true color
How do you make something perpendicular
Would “not” be an adjective in this sentence: “The pen does not work”