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

which is the main way a representative democracy differs from a direct democracy
Element used to make first atomic bomb
What is 10% off £1.80?
Eight less than a number is no more than 14 and no less than 5
how did the akkadian empire form
What is the solution to the system of linear equations y-x=4 and y+2x=1?
What are the major tissues of the gallbladder?
Should secret wiretapping be legal
Evaluate the expression when x = –12. 3x – 17 a. –53 b. –19 c. 19 d. 53
Which characteristics do cell membranes and cell walls have in common?