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

One Step Equations. One Step Addition. 1) x + 4 = 3 2) x + 7 = -3 3) x + 9 = 14
¿Qué trata de comunicar el autor cuando dice que uno de los cadáveres “ocupó el mismo escalón jerárquico” [líneas 49–50]? A. Que ocupaba un alto cargo B. Que
Which statement best describes the benefits of a city-state? O A It governed surrounding lands and had its own ruler. B. It prevented wars with neighboring citi
Read and look at this graphic from citizenship. What is the central idea of the excerpt? ​
A $600 deposit for 30 years at a simple interest rate of 2%​
Given the general form of linear systems a1x + b1y=c1 and a2x+b2y=c2 What is the correct solution using determinant in terms of a,b, and c
Review Page 142, What does Percy learn from the Oracle?
A voter in North Carolina has a good idea for a new federal law. Which of the following is NOT a step in getting it passed? A. A member of Congress must draft
Find the side length s of the square. Please help
What is the purpose of using subheadings as a text feature in your writing? increases reading comprehension introduces new information organizes the information