Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70427
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: symple programming task |
| Date | 2014-04-20 21:11 +0200 |
| Organization | None |
| References | <cc416b4b-e19d-49b9-abc2-86bcff455f9c@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9385.1398021090.18130.python-list@python.org> (permalink) |
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.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
symple programming task Ivan Ivanivich <ivriabtsov@gmail.com> - 2014-04-20 11:43 -0700
Re: symple programming task Chris Angelico <rosuav@gmail.com> - 2014-04-21 05:02 +1000
Re: symple programming task Peter Otten <__peter__@web.de> - 2014-04-20 21:11 +0200
Re: symple programming task Joel Goldstick <joel.goldstick@gmail.com> - 2014-04-20 15:15 -0400
Re: symple programming task Ivan Ivanivich <ivriabtsov@gmail.com> - 2014-04-20 12:27 -0700
Re: symple programming task Joshua Landau <joshua@landau.ws> - 2014-04-21 12:43 +0100
Re: symple programming task Ivan Ivanivich <ivriabtsov@gmail.com> - 2014-04-21 06:21 -0700
Re: symple programming task Tim Chase <python.list@tim.thechases.com> - 2014-04-21 08:39 -0500
Re: symple programming task Chris Angelico <rosuav@gmail.com> - 2014-04-21 23:43 +1000
csiph-web