Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #70459

Re: symple programming task

Newsgroups comp.lang.python
Date 2014-04-21 06:21 -0700
References <cc416b4b-e19d-49b9-abc2-86bcff455f9c@googlegroups.com>
Message-ID <7f496a70-6b85-4bc9-bf33-7aeaad813d11@googlegroups.com> (permalink)
Subject Re: symple programming task
From Ivan Ivanivich <ivriabtsov@gmail.com>

Show all headers | View raw


On Sunday, April 20, 2014 10:43:37 PM UTC+4, 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
> 
> 
> 
> 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?
> 
> 
> 
> thanks
> 
> 
> 
> sorry for my english

my bag is: Adding twice the same elements to the total

for exemple:

for divider in 3, 5:
        basis=divider
        while basis < 1000:
                mod = basis % divider
                if mod == 0:
                        total = total + basis

if "basis" is 15, then "mod" == 0 twice - when the "divider" is 3 and 15

my new version of script:

total = 0
div1 = 3
div2 = 5
for basis in range(0, 1000):
        mod = basis % div1
        if mod == 0:
                total = total + basis
                continue
        mod = basis % div2
        if mod == 0:
                total = total + basis
                continue



print("total = ", total)

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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