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

Complete the sentences below that describe the process of dune movement. Note that some terms will remain unused. View Available Hint(s): saltation, windward,
how to solve 2x + 3 = 4(x - 1 )
(Ud.) / salir antes de las cinco
How many terms did Franklin D. Roosevelt serve as the United States President?
Find the sum of the arithmetic sequence. 3, 5, 7, 9, ..., 21
In which of the following ways are bacteria similar to birds
A variety of pure-breeding snapdragons produces a tall plant with green seeds (WWSS). A second variety of pure-breeding snapdragons produce a short plant with w
Based on FAA estimates the average age of the fleets of the 10 largest U.S. commercial passenger carriers is 13.4 years with a standard deviation of 1.7 years.
A(n) ______________________ disorder is diagnosed when disruptions in personal identity, awareness, or memory are extreme, frequent, and seriously impair the ab
What is the exponential function in figure ?