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

4.   Which aquatic ecosystem typically forms along coastlines where fresh water and salt water meet, leading to varying degrees of salinity?
help me please I'm stuck
Identify and explain four types of risky behaviour amongst teenagers by means of an example
Multiple choice: Express the complex number in trigonometric form. -2 Even if you guess its probably better than my guess 2(cos 90° + i sin 90°)  2(cos 0° + i
Find the distance between the given points. A(5, 3) and B(7, -4) Distance =
The perimeter of a rectangle is 72 inches. Find the dimensions if its length is 2 inches greater than its width. Be sure to write an algebra equation
What is -5x+8(y+x)=11 in standard form?
Which type of ad is most similar to snob appeal? A. testimonial B. glittering generalities C. cutting edge D. omission
explain how ray ab an ac form both a line and an angle
What were the reasons for the revolts and rebellions that occurred in the colonies of virginia, maryland, massachusetts, and new york between 1660 and 1700? how