Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'scripts': 0.03; 'output': 0.05; 'say,': 0.05; '1000.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'wrote': 0.14; 'ivan': 0.16; 'multiples': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:programming': 0.16; 'task:': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'all,': 0.19; 'programming': 0.22; 'header:User-Agent:1': 0.23; 'closely': 0.24; 'script.': 0.24; 'fine': 0.24; 'script': 0.25; 'compare': 0.26; 'task': 0.26; 'header:X-Complaints-To:1': 0.27; 'returned': 0.30; 'calculated': 0.31; 'mod': 0.31; 'skip:# 10': 0.33; 'problem': 0.35; 'but': 0.35; 'list': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'numbers': 0.61; 'simple': 0.61; 'sum': 0.64; 'total': 0.65; 'natural': 0.68; '20,': 0.68; 'basis)': 0.84; 'total,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: symple programming task Date: Sun, 20 Apr 2014 21:11:09 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bdb3b9.dip0.t-ipconnect.de User-Agent: KNode/4.11.5 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1398021090 news.xs4all.nl 2862 [2001:888:2000:d::a6]:42306 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:70427 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.