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

Britten used the different families of the orchestra to help define the structure of the young person's guide to the orchestra
Please help me?? With understandable explanation
Suppose that in a wave of pessimism, housing prices fall by 10% across the entire economy. a. has the stock of real assets of the economy changed?
At a pond there were 24 ducks swimming. The ratio of ducklings to adult ducks is 5:1. How many ducklings were swimming at the pond?
Lola is currently paying $445.16 per month for 5 years on a $15,999 car. how much will she pay in interest?
Mia kaminsky wants to attend riverside community college. she'll need to have $25,000 six years from today. mia is wondering what she'll have to put in the bank
help meeeeeeeeeeeeeeeeeeeee
the sum of two and the quotient of a number x and 5
To be specific, estimate the diameter of a 1-ton rock, but first make a wild guess: will it be 1 ft across, 3 ft, or the size of a car? [hint: rock has mass per
Which specialists are the most likely to prescribe a drug for the treatment of a psychological disorder?