Westonci.ca offers fast, accurate answers to your questions. Join our community and get the insights you need now. Explore in-depth answers to your questions from a knowledgeable community of experts across different fields. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately.

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

Thank you for your visit. We're committed to providing you with the best information available. Return anytime for more. We appreciate your time. Please revisit us for more reliable answers to any questions you may have. Thank you for using Westonci.ca. Come back for more in-depth answers to all your queries.