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

An airplane flies at 440 miles per hour. How fast is it flying in feet per second?
what is 10 more than 56
Given: AB is the perpendicular bisector of IK. Name two lengths that are equal
German U-boats stood by the Sussex Pledge. true or false
All of the following were goals of the Tehran Conference EXCEPT which one? A. to plan the invasion of France B. to form plans for Europe after the war C. to dis
write the equation in standard form: 3x-9=7y
Which best summarizes the flow of energy in a producer? Sun à ADP à muscle cells Sun à mitochondria à C6H12O6 Sun à chloroplasts à mitochondria Sun à mitochondr
Which terrestrial planet experiences the shortest year? A. Mars B. Earth C. Venus D. Mercury
Which of the following best describes the British position toward Native Americans after the Revolutionary War?
why did the math teacher open a window company?