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

Freddy is searching for a shirt and discovers that he has 12 shirts for every 6 pair of jeans.If he has 18 shirts, how many pairs of jeans does he have?
i need a sentence with patriotically
Which statement about changes that occurred during the Industrial Revolution is true? A. Many people moved from farms and small towns to cities to find employ
find the zeros of the function f(x)=2x^2-7x-30
What Chinese dynasty rebuilt the city of beijing?
St. Paul was a follower of Jesus who spread Jesus’ teachings to people other than the Jews. St. Paul thought of himself as an apostle to which of these people?
What Is a group of mussels called
The richest discovery in the history of mining occurred in 1873. This so-called "Big Bonanza" made _______ the richest man in the world. A. John Mackay B. John
the Wilson's garden covers 5/8 acre. one fourth of the garden is planted with flowers. the rest is vegetables. what part of an acre is planted with flowers? wit
Which describes the Anasazi or ancestral Pueblo Indians of the Southwest? A. lived in cliffside caves or adobe dwellings B. lived near the water and celebrated