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


Groups > comp.lang.python > #77361

Re: This could be an interesting error

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin.stu.neva.ru!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:error': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'assignment': 0.07; 'sys': 0.07; '22,': 0.09; 'lawrence': 0.09; 'prefix': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'referenced': 0.09; 'sentence': 0.09; 'python': 0.11; 'def': 0.12; 'assume': 0.14; 'language.': 0.14; 'random': 0.14; 'brackets.': 0.16; 'line)': 0.16; 'loops': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'stem': 0.16; 'exception': 0.16; 'language': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'seems': 0.21; 'input': 0.22; 'import': 0.22; '(in': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'rid': 0.24; 'math': 0.24; 'gets': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'code': 0.31; 'usually': 0.31; '25,': 0.31; '>>>>': 0.31; 'file': 0.32; '(most': 0.33; 'test': 0.35; 'done': 0.36; 'to:addr:python-list': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'read': 0.60; 'break': 0.61; 'first': 0.61; 'our': 0.64; 'charset:windows-1252': 0.65; 'subject:This': 0.74; 'subject:interesting': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: This could be an interesting error
Date Sun, 31 Aug 2014 22:38:12 +0100
References <pm270ap6g01k6a5ip10ij1lgtebsrv00mr@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-78-146-3-67.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0
In-Reply-To <pm270ap6g01k6a5ip10ij1lgtebsrv00mr@4ax.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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>
Newsgroups comp.lang.python
Message-ID <mailman.13666.1409521108.18130.python-list@python.org> (permalink)
Lines 65
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1409521108 news.xs4all.nl 2945 [2001:888:2000:d::a6]:37333
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:77361

Show key headers only | View raw


On 31/08/2014 22:02, Seymore4Head wrote:
> import math
> import random
> import sys
>
> ex='Hey buddy get away from the car'
> newex = ex.split()
> sentence=""
>
> print (newex)
> wait = input ("          Wait")
>
> def pigword(test):
>      for x in range(len(test)):

Please read up on how to use for loops as the above is usually a code smell.

>          if test[x] in "AEIOUaeiou":
>              stem = test [x:]
>              prefix = test [:x]
>              pigword = stem + prefix + "ay"
>              print ("Stem ",stem)
>              print ("Prefix",prefix)
>              print (pigword)
>              break
>      return (pigword)

This is Python so please get rid of those unnecessary brackets.  Having 
done that assume that you have an empty test so your loop never gets 
entered, the local pigword never gets assigned before the return hence 
your UnboundLocalError.

>
> for x in range(len(newex)):

Ditto.

>      sentence = sentence + pigword(newex[x])+ " "
>      print (sentence)
>      wait = input ("          Wait")
>
> The program seems to work and it does work with everything I have
> tried so far.  The one exception is if you change "the" to "my" (in
> the first line) the program crashes.
>
>
> Traceback (most recent call last):
>    File "C:\Documents and
> Settings\Administrator\Desktop\Functions\test.py", line 25, in
> <module>
>      sentence = sentence + pigword(newex[x])+ " "
>    File "C:\Documents and
> Settings\Administrator\Desktop\Functions\test.py", line 22, in pigword
>      return (pigword)
> UnboundLocalError: local variable 'pigword' referenced before
> assignment
>>>>


-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Thread

This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 17:02 -0400
  Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 17:07 -0400
  Re: This could be an interesting error Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-31 22:38 +0100
    Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 18:04 -0400
      Re: This could be an interesting error Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-31 23:26 +0100
    Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 18:42 -0400
      Re: This could be an interesting error Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-01 00:21 +0100
        Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 20:08 -0400
          Re: This could be an interesting error Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-01 01:56 +0100
            Re: This could be an interesting error Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-01 12:53 +1000
              Re: This could be an interesting error Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-01 07:34 +0100
          Re: This could be an interesting error Ned Batchelder <ned@nedbatchelder.com> - 2014-08-31 22:12 -0400
            Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 22:54 -0400
              Re: This could be an interesting error Larry Hudson <orgnut@yahoo.com> - 2014-08-31 21:55 -0700
                Re: This could be an interesting error Chris Angelico <rosuav@gmail.com> - 2014-09-01 15:12 +1000
                Re: This could be an interesting error Rustom Mody <rustompmody@gmail.com> - 2014-08-31 23:53 -0700
  Re: This could be an interesting error MRAB <python@mrabarnett.plus.com> - 2014-08-31 22:53 +0100
    Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 18:07 -0400
      Re: This could be an interesting error Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-01 12:12 +1000
        Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 22:13 -0400
        Re: This could be an interesting error Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-09-01 19:25 +1200
  Re: This could be an interesting error Michael Torrie <torriem@gmail.com> - 2014-08-31 16:10 -0600
    Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 18:31 -0400
    Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 20:04 -0400
      Re: This could be an interesting error MRAB <python@mrabarnett.plus.com> - 2014-09-01 01:23 +0100
        Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 20:35 -0400
      Re: This could be an interesting error Michael Torrie <torriem@gmail.com> - 2014-08-31 22:15 -0600
      Re: This could be an interesting error Michael Torrie <torriem@gmail.com> - 2014-08-31 22:52 -0600

csiph-web