Westonci.ca is the premier destination for reliable answers to your questions, provided by a community of experts. Our Q&A platform provides quick and trustworthy answers to your questions from experienced professionals in different areas of expertise. 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

We appreciate your visit. Hopefully, the answers you found were beneficial. Don't hesitate to come back for more information. Thank you for choosing our platform. We're dedicated to providing the best answers for all your questions. Visit us again. Find reliable answers at Westonci.ca. Visit us again for the latest updates and expert advice.