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

Find the measure of x (WILL GIVE BRAINLIEST)
Brianna used two congruent parallelograms and a square to create the figure shown. NIM ft ft
Medical doctors and nurses often O speak in simple terms. O believe their explanations are clear. do not care if instructions are followed properly. O underesti
Please help this is a test you in5 minutes I really need help I’ll give 10 points
Could someone explain to me how to get the equation for slope off of a graph? It would be greatly appreciated:)
This is really easy!!!!!! Will give brainlist!!!! Btw question is in photo!
what is the volume of Copper and Zinc used to make the grass​
rob is saving to buy a new mp3 player. for every $15 he earns babysitting, he saves $8. On Saturday, Rob earned $90 babysitting. how much money did he save?
What's the grammatical function of an adverb?To describe a nounTo describe a action To show an occurrenceTo name something​
im not sure of my answer i need help please!!