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

If light travels 671,000,000 miles per hour, how many miles will it travel in one minute?
It takes Akira 10 minutes to make a black and white drawing and 25 minutes for a color drawing.  On Saturday he made a total of 9 drawings in 2 hours.  Write an
find the area of a circle with a diameter of 22 inches?
It takes Akira 10 minutes to make a black and white drawing and 25 minutes for a color drawing.  On Saturday he made a total of 9 drawings in 2 hours.  Write an
Taylor wants to make 2 1/2 times the quantity given in a recipe. The recipe calls for 1 3/4 cups of flour. How much flour will Taylor need?
what is x3+3x2-x-3 factor by grouping
McDonald's has sold more than a billion hamburgers. If it were possible to eat a hamburger every minute of everyday (day and night) without stopping, how many y
Taylor wants to make 2 1/2 times the quantity given in a recipe. The recipe calls for 1 3/4 cups of flour. How much flour will Taylor need?
graph x+2 is greater than -2
Geoffrey ate  2/3 of a mini pizza. Claire ate 1 3/4  times as much pizza as Geoffrey.  How many mini pizzas did Claire eat? Express your answer in simplest form