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

A religion that values silence and wordless meditation is
When people from an industry go to work for the agency regulating that industry, this movement is called?
Mary rent a truck from a truck-rental company that charges a flat fee of $20 and $5 per hour. If Mary rents the truck for h hours, the expression that shows the
Which sentence is correctly punctuated? A- Dedicated in May, 1922, the Lincoln Memorial, was built to honor Abraham Lincoln. B- Dedicated in May 1922 the Lincol
What is the solution to 8^x = 3^ x+2
What is the greatest common factor of 24 and 40?
Help me please! Will give brainly to correct answer.
Which of the following is not a layer of the atmosphere? (4 points) Select one: a. Troposphere b. Stratosphere c. Mesosphere d. Hydrosphere
What is an example of a graphic organizer? A. map B. illustration C. chart D. photograph
Which of the following is not true about enzymes? a. They are consumed by the reactions they catalyze. b. They are usually made of amino acids. c. The