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

Fill in the blank with the word that best completes the sentence: The group of tourists to Yellowstone National Park ______ out of the bus to take pictures of O
A quadratic polynomial has a degree greater than 2? True or false
how would I find the area and perimeters ​
PLEASE HELP ASAP!!!!! ∆XYZ has vertices X(0, 3), Y(2, 0), and Z(4, 2). If you reflect ∆XYZ across the line x = 4, what will be the coordinates of the vertices o
Evaluate the function f(x) = x2 +1 for f(2). 1 5 7
Neil is currently twice the age of his brother when Neil was born. The sum of their ages will be 98 when Neil is as old as his brother's current age. How old ar
Which sentence uses correct punctuation and capitalization within parentheses? My brother (He has read hundreds of books on the subject.) told me that the samur
Franz and his friends are using the spinners below to play a game
Find the value of z such that 0.9722 of the area lies between −z and z. Round your answer to two decimal places.
simplify (2a−4b)+2(a−4b)