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

Leslie contracts with Remodel, Inc., to redo her living room, but she changes her mind and breaches the contract before Remodel can begin work. As a remedy for
rounding 0.912 to the nearest hundredth
why was the Proclamation of 1763 issued?
12 women/41 men= 31 women/n men
How are electrons moved from photosystem II to photosystem I in photosynthesis?
Which new weapon was introduced during the Hundred Years' War? A. rifle B. crossbow C. armor D. longbow
Getty markets has bonds outstanding that pays a 5 percent semiannual coupon, have a 5.28 percent yield to maturity, and a face value of $1,000. the current rate
the quotient of 2 times a number and 19
you and your friend are standing back-to-back. your friend runs 16 feet forward than 12 feet right. at the same time, you run 12 feet forward and then 9 feet ri
Find the missing geometric means in this sequence.