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

The graph shows two lines, A and B: A graph is shown with x- and y-axes labeled from 0 to 6 at increments of 1. A straight line labeled A joins the ordered pair
How was the economic situation in the United States different than in European nations in the 1920s?
Which does the underlined clause modify? Could I have that book when you are finished with it? A.could have B.have C.could D.book
Which word in the sentence, if any, should be followed by a comma? I will see you in the morning my friends. A. morning B. There is no error in comma usage.
The roots of the Orthodox Church are in ?
Find the value of x that makes the equation true. 9x = –54 A.6 B.–9 C.–6 D.–54
what operation should be performed first to solve -3x+5<23
What two human systems work together to provide body cells with a constant supply of oxygen while removing carbon dioxide waste products?
cuando cierras las ventanas
In his book Common Sense, Thomas Paine begins to make the colonists think about becoming: A. Kings B. Communist C. Independent D. Loyalists