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

How do you think the Industrial Revolution and the Gilded Age impacted his ideas?
Susanne has no money. In order to buy her sister a gift, she borrowed $15 from her mom. When her birthday came, she received $45 dollars. If she repays her mom,
I NEED SOME HELP NOW, PLS THIS IS MY LAST PROBLEM OF THE DAY!! I WILL GIVE YOU BRAINLEST IF YOU ANSWER IT!!!
hellllllllllllppppppp​
are 1/2 and 8/16 equivalent rates?
How would Nya's life had been effected if Salva wouldn't have come to her village?
Which part of Act II would be considered a complicating incident? Maria plans with Sir Toby to plant a false love letter from Olivia to Malvolio. The Duke gives
Recordar (my friends and I)
Can someone translate this audio? It is in the PowerPoint. I have written how to hear the audio on the first slide (there are 2 in total). Thanks.
Write your return address as it should appear on an envelope. Be sure to use commas correctly in the address.