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

how will you make a cheer dance routine in a solo performance
Mike made lemonade. First, he poured a glass of water. Next, he stirred in two tablespoons of sugar. Finally, he stirred in a little lemon juice.Question:Descri
im toooo bad at math plz help
the rational and reasonable part of personality is known as the
Question 2 What do you think the resulting equation from part D in question 1 means for the value of the variable s?
Is the population pyramid of Italy 1998 increasing or decreasing
Select the correct image. Which structure is a valid representation of a hydrocarbon molecule? Н H-C-H Н Н H Н 1 1 1 1 H-C-C С -С-С-Н 1 1 1 1 1 Н Н Н Н Н Н 1 H-
What is the equation in slope-intercept form of a line that is perpendicular to y=2x+2 and passes through the point (4, 3)? PLS HELP FAST HELP REALLY FAST PLEAS
COULD-COULDN'T-COULD...?
cuales son las clases de ondas de radio