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

Kelly drew the angle shown, which value is closest to measurement of Kelly's angle?
PLEASE HELP WILL MARK BRAINLIEST
if this is the given data 24, 12, 19, 26, 19, 20, 15, 17 what is the median​
The primary site of photosynthesis fruits roots leaves flowers
Someone help plz and make sure its right
What is the FNAF timeline
PLEASE ANSWER ASAP!!! Graph the following sets of points on a number line. y≥3 and y≤-2
ナルトが好きな人はいますか?あなたの好きなキャラクターは誰ですか?
I will mark u brainalist
consumer behaviour of poor class of pakistan