Get comprehensive solutions to your problems with IDNLearn.com. Discover the information you need from our experienced professionals who provide accurate and reliable answers to all your questions.

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


Sagot :

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