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

PLEASE HELP ME ASAP! I NEED HELP PLEASE! I need help with question number 35 please! ​
what is the slope for (6,2) (9,8)
А_is an area of land that rises very high above the land around it. lake mountain plain Oriver
This is for chemistry I need help for this question
What occurs during G1 and G2 in the cell cycle? A) synthesis of the cell B) growth of DNA C) growth of the cell
pls help me out pls it is dou in a few minutes ​
can you put 92 80 88 100 94 98 72 80 94 86 in order
13 = 11 + u I need work and answer!!!
Find the unknown term in the proportion 4:7 =24:x
Brian has $30 in his piggy bank. He earns $10 a week at his job. Sarah has $10 in her piggy bank and earns $20 a week at her job. In how many weeks will they ha