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

A box contains three marbles: one red, one green, and one blue. Consider an exper-iment that consists of taking one marble from the box then replacing it in the
You gently place several steel needles on the free surface of the water in a large tank. The needles come in two lengths: some are 5 cm long, and some are 10 cm
how do i find XY??????
angie designs an experiment to investigate different types of music
Insert <, >, or = in the appropriate space to make a true statement. |-11 _-8
An object moves in a circle at a constant speed of 1.0 m/s. The radius of the circle is 1.0 m. If a force of 1.0 N acts toward the center of the circle, how muc
A drowsy cat spots a flowerpot that sails first up and then down past an open window. The pot is in view for a total of 0.50 s, and the top-to-bottom height of
Which example would be best formatted as a persuasive message? (A) Customer-service survey results Information about failure to follow procedures (B) Encouragem
What is the answer for 20 x 3/4=
The earliest land plants were liveworts, misses and frem. Why do you think that these plants were successful in the humid and most ancient environment?