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 a potential barrier?
What should you consider when evaluating your writing for word choice?
Mi primo es el___________de mi prima. A. primo B. hermano C. padre D. abuelo
The given problem refers to right triangle ABC with C = 90°. Use the given information to find the exact value of the six trigonometric functions of A. b = 15,
4 5 6 7 8 10 The point from which all other lines of latitude measure distance is called__________. a. the absolute location b. the North Pole c. the P
Why did the roman monarchy fall?
Help me :( 1. Which belief of socialism may have been influenced by what was happening during the industrial revolution ? A. the government should never inter
if 75.0 g silderite ore (FeCO3) is heated with an excess of oxygen, 45.0 g of ferric oxide (Fe2O3) is produced. 4FeCO3(s) + O2(g) → 2Fe2O3(s) + 4CO2(g) What is
Hoofed animals have the least maneuverable digits. What are some positives to having hoofs instead of hands and feet with fingers and toes?
What is a of events that cells go through as they grow and divide ?