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

Help me! please.. What is the importance and effect of the Americanization movement?​
The Wing Station wants the average price of the lunch meal deals to be $8. Lunch Meal Deal Prices Item Price ($) Deluxe hamburger $9 Reuben sandwich $7 Chick
Explain in your own words how the marketers went about selling the idea of the mms to the public
Translate into a variable expression. 1. seven-eighths of the sum of y and 1 2.(Use x for your variable) the sum of three-tenths of a number and fourteen
what is -8 (x - 1) = -32
whats ski mask first ever song​
What is a segment of dna that contains a single cell unit of information
Which type of statement is related to implying meaning? Explicit Exposed Implicit Imputed
How can formal business documents help managers solve problems? A. By presenting well-organized, accurate information about a problem B. By creating a record o
Park rangers tagged fish in a state park to track their population. The function f(x)=200(1.05)x can be used to find the population of fish after x years. 1. Wh