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

Read the following excerpt from E. O. Wilson’s “The Environmental Ethic.” Species are disappearing at an accelerating rate through human action, primarily habit
PLZ HELP Write an equation of the given line in slope-intercept form with the given points (1,1) and (4,2)
The weight of body is 420 N. Calculate is mass0.34 m 11.67,000 g 1,72.800 s 1 dayLOSSARYthe ratio of mass and volumethe rate of change of velothe rate of displa
Hello!Can someone please translate this?picture is given!...​
Brianna buys 10 balloons for her sisters. She gives 5 balloons to each sister and has none left. How many sisters doe Brianna have?​
You are curious whether or not the following two events meet the standard criteria in statistics for mutually exclusive events: January sales exceeding $1 mill
Quels sont les inconvénients de vivre en ville???
HELP please :) a laptop costs $899 how much will it be with a sale of 24% off
Using the formula y=ab/2c, express: the variable c in terms of a, b, and y.
Type the correct answer in each box. The point on the number line shows the opposite of , or the opposite of the opposite of .