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

how could having a prescription for a legal drug lead to illicit drug use?
When planning a personal interview with a source, it is best to: A. contact the interviewee in writing. B. be mindful of the interviewee’s allotted time. C. alw
who is the protagonist in "the battle with the dragon"
What is the derivative of y=tan(arcsin(x))?
Which statement describes what Congresswoman Chisholm thinks should be done to overcome prejudice? A. Laws can change deep-seated problems over time. B. Legisla
what is 10 3/8 divided by 3/8 estimated?
1/4+1/2 find the sum using number line
what did dmitri mendeleev do?
Which revision most effectively corrects the faulty parallelism in this sentence? William Shakespeare was an actor, a playwright, and he also wrote poetry. a-W
The difference of a positive integer and its inverse is 15/4. Find the integer.