total_sum = 0 for i in range(1000): if (i%3 == 0 or i%5 == 0): total_sum = total_sum+i print total_sum
You should leave your numbers, variables and operators some space to breathe by adding some horizontal space between them which improves readability a lot.
total_sum = 0
for i in range(1000):
if (i % 3 == 0 or i % 5 == 0):
total_sum = total_sum + i
print total_sum
As natural numbers aren't explictly defined containgcontaining 0
you could also use a start
parameterthe two-parameter form of the range()
function and specify the range()start
methodparameter like so
total_sum = 0
for i in range(1, 1000):
if (i % 3 == 0 or i % 5 == 0):
total_sum = total_sum + i
print total_sum