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 unit of length is used to express the size of stars?
The political balance between slave and free states as of 1819 was disturbed by:
explain how you can use a quick picture to find 3x2.7
why does the president usually urge voters to elect members of the president's own political party to congress
What is the relationship between return and risk? * a. Investments with high returns are lower risk. b. Investments with low risk have lower returns. c. Inves
What is the quotient of 787/2 then estimate
write a real word problem that gives extra information
Which one of the following sentences is written in the active voice? A. It is said that definite steps can be taken to prevent many accidents. B. Accidents are
Rheumatoid arthritis is caused by: a bacteria a virus a reaction to an immunization an autoimmune reaction
Which of the following was NOT a reason for the British to colonize North America?