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

current beliefs as to why people age
Who were the mercenaries that fought with the british army in the revolutionary war?
True or False- Turkeys can drown if they look up in the rain.
The three main ideas behind capitalism as defined by Adam Smith are free markets, laissez-faire, and fair taxes. competition, self interest, and laissez-faire.
for how long can muscles rely soley on lactic acid fermentation to generate ATP
When European countries occupied and partitioned Middle Eastern lands, all of the following effects occurred except __________. A. a desire to make the Middle E
what is the sum of 3/8 + 1/16
All living things need energy; it is a requirement for life. In a typical cell, ATP, the high energy molecule, is produced in the __________ in the presence of
How would you describe Jedediah Smith? What do you think were his most important characteristics?
what can be found in the computer tower