prasad rao wrote:
hi
I got it right.
>>> z=[]
>>> for x in range(1000):
if divmod(x,3)[1]==0:z.append(x)
if divmod(x,5)[1]==0:z.append(x)
>>> sum(set(z))
233168
Instead of using the set function you could just use an elif in your for
loop.
>>> z=[]
>>> for x in range(1000):
if divmod(x,3)[1]==0:z.append(x)
elif divmod(x,5)[1]==0:z.append(x)
>>> sum(z)
233168
or as somebody else suggested use an OR operator
>>> z=[]
>>> for x in range(1000):
if (divmod(x,3)[1]==0) or (divmod(x,5)[1]==0):
z.append(x)
>>> sum(z)
233168
just some variations... On an other wise correct anwser.
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor