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 is the product (7x10^-5) (5x10^-8)
Which statement is accurate regarding class and citizenship in the Roman Republic? Plebeians held the highest offices in government. Anyone who lived in Rome c
Please help Spanish Imagine your parents have left you in charge and left you a list of things for you and your siblings (Elenor y Mario) to do to prepare for g
From these choices, select the best definition of the word "beneficial," using context clues to determine meaning. Many believe in the beneficial health effects
Which of the following claims about the TYR, TRP2, and TRP1 mammalian genes is most likely to be accurate? a-The TYR, TRP2, and TRP1 genes are located next to e
Charles is camping. His campsite is 7/8 miles away. He walks at a speed of 1 7/8 miles per hour. How many minutes will it take him to get to the campsite.
What is the percent composition of phosphoric acid (H3PO4)?
The pea aphid, a type of insect, contains light-capturing pigments in its exoskeleton. Pea aphids gained the ability to synthesize these pigments from genes tra
ANSWER FAST PLZ 25POINTS!!!!!!!!!!!
a standard number cube is rolled one time what is p(rolling)2​