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


Groups > comp.lang.python > #101207

Re: Consistent error

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: Consistent error
Date Mon, 4 Jan 2016 01:47:45 +1100
Lines 41
Message-ID <mailman.205.1451832473.11925.python-list@python.org> (permalink)
References <6f54629c-745f-4f75-a267-0f174cc1aea1@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de gZJwujp8fAq+cGKwwo8yFQBgBEOrwL0xgMAZqfG0hsOQ==
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'cc:addr:python-list': 0.09; 'it;': 0.09; 'python': 0.10; 'jan': 0.11; 'subject:error': 0.11; 'def': 0.13; 'subsequent': 0.15; '2016': 0.16; 'executed.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'partly': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sure.': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'algorithm': 0.20; 'meant': 0.22; 'am,': 0.23; 'bit': 0.23; 'this:': 0.23; 'second': 0.24; 'header :In-Reply-To:1': 0.24; 'mon,': 0.24; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'indentation': 0.29; "i'm": 0.30; 'print': 0.30; 'comments': 0.30; 'code': 0.30; 'largest': 0.31; 'maybe': 0.33; 'problem': 0.33; 'received:google.com': 0.35; 'something': 0.35; 'received:209.85': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'your': 0.60; 'show': 0.62; 'statement,': 0.66; 'chrisa': 0.84; 'divide': 0.84; 'uncertain': 0.84; 'to:none': 0.91; 'careful': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=tWL/N92kJyHSV3ggknsOuSmXuZqx2tPXxbKvpRQwivU=; b=SPRrEW4J4sXhr185GbdQhYGtPal1fGBxAh3F7aF0/hGh2vMQIRGwemBijh7WiApYI6 /E5qWaGRjSUyRq31/jkI+VkhhuOOTkuHymYsPqTCcm7phB0xDu4fELWxBWU1KE7pvm4R sxJkTVaN2lZ8v/qoHEIA+jZlEoZN7FFbURIAZ3wXzb3HFSobPH/NmEIQaK7/40QmZ+ax OAj0bYNzkJ06GByFDh+RnTvvIBSjjFhMgmJ9rHf21QNSxLlaEwG25U0iBEbqC8GevGHV hifdDSrMnXRIa1zRXMPGHxW50xH4F52DHcF/snkpei9GxBUZci2HLEQoifPbreZiN1jo It2w==
X-Received by 10.50.78.70 with SMTP id z6mr31801888igw.92.1451832465549; Sun, 03 Jan 2016 06:47:45 -0800 (PST)
In-Reply-To <6f54629c-745f-4f75-a267-0f174cc1aea1@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:101207

Show key headers only | View raw


On Mon, Jan 4, 2016 at 1:35 AM,  <cc.fezeribe@gmail.com> wrote:
> Here's my code in python :
>
> def get_algorithm_result( numlist ):
>  largest = numlist[0]
>  i = 1
>  while ( i < len(numlist) ):
>    if ( largest < numlist[i]):
>      largest = numlist[i]
>      i = i + 1
>      numlist[i] = numlist[-1]
>      return largest
>      numlist = [1,2,3,4,5]
>      largest = get_algorithm_result(numlist)
>      print largest
> def prime_number(x):
>  return len([n for n in range(1, x + 1) if x % n == 0]) <= 2

I'm a bit uncertain of your indentation here, partly because there's
so little of it; what happens in the while loop if the 'if' condition
is false?

After a 'return' statement, nothing will be executed. If you write
code like this:

if some_condition:
    do_stuff()
    return something
    do_more_stuff()

the second call will never happen - the function will immediately bail
out. Maybe you meant for the subsequent code to be unindented? I'm not
sure.

Have a very careful read of your requirements, and try to lay your
code out the exact same way. Put comments against each block of code
to show which part of the required algorithm it's performing. That
way, you divide the problem up some, and you can look at each piece
separately.

ChrisA

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


Thread

Consistent error cc.fezeribe@gmail.com - 2016-01-03 06:35 -0800
  Re: Consistent error Chris Angelico <rosuav@gmail.com> - 2016-01-04 01:47 +1100
    Re: Consistent error cc.fezeribe@gmail.com - 2016-01-03 07:59 -0800
      Re: Consistent error Chris Angelico <rosuav@gmail.com> - 2016-01-04 03:14 +1100
        Re: Consistent error cc.fezeribe@gmail.com - 2016-01-03 08:55 -0800
          Re: Consistent error Alister <alister.ware@ntlworld.com> - 2016-01-03 18:22 +0000
      Re: Consistent error Ian Kelly <ian.g.kelly@gmail.com> - 2016-01-03 09:27 -0700
        Re: Consistent error cc.fezeribe@gmail.com - 2016-01-03 08:59 -0800
          Re: Consistent error iykeluvzu@gmail.com - 2016-01-15 06:15 -0800

csiph-web