Welcome to Westonci.ca, where your questions are met with accurate answers from a community of experts and enthusiasts. Experience the convenience of getting accurate answers to your questions from a dedicated community of professionals. Explore comprehensive solutions to your questions from knowledgeable professionals across various fields on our platform.

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