symple programming task

Peter Otten __peter__ at web.de
Sun Apr 20 15:11:09 EDT 2014


Ivan Ivanivich wrote:

> hi all, i have simple programming task:
> 
> [quot]
> If we list all the natural numbers below 10 that are multiples of 3 or 5,
> we get 3, 5, 6 and 9. The sum of these multiples is 23.
> 
> Find the sum of all the multiples of 3 or 5 below 1000.
> [/quote]
> 
> this task from http://projecteuler.net/ site
> 
> I wrote a solution in python
> 
> http://pastebin.com/QXtNuRWU

[for small scripts it is fine to include them directly in your post]

> #!/usr/bin/env python3.2
> 
> total = 0
> for divider in 3, 5:
>         basis=divider
>         while basis < 1000:
>                 mod = basis % divider
>                 if mod == 0:
>                         total = total + basis
>                         print("total = ", total, "basis = ", basis)
> 
>                 basis += 1
> 
> print("total", total)



> this script returned correctly result if "basis < 10", but if "basis <
> 1000" result is 266333 and it is not correctly answer on site
> http://projecteuler.net
> 
> it is my script problem or site not working correctly?

Your script. Try it for the numbers below 20, say, and then compare to a 
result you calculated with pen and paper.

Or look closely at the output produced by the line

> print("total = ", total, "basis = ", basis)

in your code.






More information about the Python-list mailing list