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

All of the following are periods within the Mesozoic era, except: Jurassic Triassic Cretaceous Cambrian
I need help with 19
should everyone go to college after high school essay​
please help meee........
What would be the most likely result of a low concentration of sugars and ions in the cell’s vacuole? The plant would oof. The plant would stop photosynthesis.
The interior of a building is in the form of cylinder of diameter 10m and height 8m, surmounted by a cone whose vertical angle is a right angle. Then what will
Which of the following best describes the role of the federal state in a country's political organization?
These types of governments attempt to control all aspects of citizens' lives (an example would be a Communist Regime, such as China)? Oligarchy Dictatorship Con
Jogging laps on a track is a ___________ activity. speed balance muscular strength cardiorespiratory
Which of these dates is the most recent? A: 50 CE B: 2000 CE C: 500 BCE D: 2000 BCE