[Tutor] project euler
Roel Schroeven
rschroev_nospam_ml at fastmail.fm
Sun Jan 4 12:57:37 CET 2009
prasad rao schreef:
> hello!
> I got it 266333.
> My code======
>
> t=0
> for x in range(1000):
> if divmod(x,3)[1]==0:t+=x
> if divmod(x,5)[1]==0:t+=x
> t=266333
>
> Am I correct in comprehention of the problem?
Not entirely: you're counting numbers that are multiples of both 3 and 5
double, which is not the intention.
BTW, instead of divmod(x, 3)[1] you can use x % 3. divmod() is nice if
you need both quotient and remainder, but if you only need the remainder
the % operator is simpler.
--
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
-- Isaac Asimov
Roel Schroeven
More information about the Tutor
mailing list