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

What is the volume of liquid in this graduated cylinder? Assume this cylinder has units in milliliters.
enrollment for college R the line graph above shows the enrollment for college R between 1950 and 2000
What is twenty-one - eighteen?
1. Calculate the number of AlCl3 that are produced from 0.25 mol of Al(OH)3. Al(OH)3 + 3HCl --> 3H2O+AlCl3 molar mass of AlCl3 = 133.3g a. 10.0g b. 33.
If a __________ tire blows out, the vehicle will pull sharply in the direction of the blowout?
Which two statements best summarize key ideas in the text? A. An increasing number of immigrants perceive serving in the military as a valid way to gain United
Fill in the blank to make a true statement. x² +_x+21 (x +_)(x + 7)
1/2 cup almond milk1 heaping cup banana1 cup strawberry1 tbsp cacao 1 pump maple syrup1 tsp almond butter1 tsp acai powder1/3 cup granola1/2 (sliced) banana1-2
A bakery used 30% more butter this month than last month. If the bakery used 250 pounds of butter last month, how much did it use this month
I NEED THIS ASAP!! We the people of the United States, In order to form a more perfect union, establish justice, insure domestic tranquility, provide for the