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

Before the Agricultural Revolution, many people lived in rural areas because
the average elevation of the city of new orleans louisiana is 0.5 m below sea level the highedt point in louisiana is driskill mountain at about 163.5 m higher
how does vegetation allow greater infiltration
How did the Holocaust contribute to ongoing Arab-Israeli conflict? a. Since so many Jewish people had been murdered in the Holocaust, many international organi
How do you say-her favourite colour is pink- in Spanish.???
The perimeter of a regular pentagon is 41.5 what is the length of all sides
Water is to moisten as spade is to dig. synonym analogy antonym analogy description analogy function analogy
what is 70/80 as a decimal
emily collected $950 selling girl scout cookies all day Saturday. emilys troop collected 10 times as much as she did.how much money did emilys troop raise?
write all names that apply to 7/8