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

Why did the Republican party became strong in the South
You live in Florida, and you have decided to prepare your home for hurricane season. Which of the following actions would LEAST help you achieve your goal? A) c
Help. Plz. Due Today.
Who killed Shawn? Long way down
PLEASE HELP QUICKLY!! Graph the equation on the coordinate plane Y = -2x (The picture might be blurry but it's just a graph with the four sections it is blank)
Evaluate the principal square root of 64
What was the main focus of Machiavelli’s book, The Prince? A It attacks the corruption of the Church. B It offers advice on acquiring and maintaining politi
Why was the introduction of the assembly line crucial to the success of the Model T?
Carbon dioxide is returned to the atmosphere primarily by theCarbon dioxide is returned to the atmosphere primarily by the
The math club is doing a fundraiser to raise money to attend a math competition. The club was told by their advisor to raise $2000, but they decided to raise $4