a simple program in python , I am stumped

92 Views Asked by At
m = 0
for i in range(1,1000):
    if i % 3 == 0 or i % 5 == 0:
        m += m
print m

This gives 0 as answer. Answer should be 233168.

Could the line ending in my IDE be an issue? I am using pycharm.

EDIT: note to self - take a break. I found the typo as soon as I posted this. I was having some problem with ide and line ending just before this. anyway thanks :) Troll away

1

There are 1 best solutions below

1
On BEST ANSWER

Note the line:

m += m

You're adding m to m itself; i.e. you're always adding 0 to 0.

You probably meant:

m += i