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's the difference between murder and execution
Is this punctuated correctly? Ms. Sardelis said we must, "absolutely and without delay" turn in our permission slips by tomorrow or we can't go on the class tri
reduce 15/24 what's the answer
What did the Sumerians use to sign their names? A. a signet ring B. stamps and ink pads C. a thumbprint D. a cylinder seal
List of weapons used by JTF2?
at the yalta conference of 1945 the military situation favored Roosevelt Churchill Eisenhower Stalin
Which archetypal character does the speaker represent in this passage? By golly, here they go and use up all the towels, every doggone one of ''''em, and they u
The sum of two consecutive integers is 37. Write an equation that models this situation and find the values of the two integers.
how much thermal energy is needed to produce 1 cubic meter of steam
True or False Feudalism originated after Charlemagne's death. True False