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 one of the following is the correct option: 4, 8, 7? Pure water has a pH of
The net of a cube is shown on the coordinate plane. What is the surface area of the cube?
who tryna talk? im board and need some one to talk to I'm real chill and I'm 16 I wanna get to know you.
the 1968 assassination of robert kennedy
A form of media used to keep a record of historical information would be called a: website newscast documentary motion picture
In the ellipse, if c=6cm, and b=8cm, what is the length of the major axis? A)10.58cm B)10cm C)20cm D)21.16cm
The number of students enrolled at a college is 12,000 and grows 6​% each year. Complete parts ​(a) through ​(e).
How did the league of nations fail?
What does it mean when different continents contain rock layers of the same age?
2. A parallel circuit has 3 resistors each on different paths connected to a 120 V potential difference. Do the resistors have resistances of 5.0 Ω, 7.5 Ω, and