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


Groups > comp.lang.python > #77362

Re: This could be an interesting error

Date 2014-08-31 22:53 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: This could be an interesting error
References <pm270ap6g01k6a5ip10ij1lgtebsrv00mr@4ax.com>
Newsgroups comp.lang.python
Message-ID <mailman.13667.1409521984.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 2014-08-31 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)):
>          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)
>
> for x in range(len(newex)):
>      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' doesn't contain a vowel, therefore the condition of the 'if'
statement in 'pigword' is never true, therefore it never binds to the
name 'pigword'.

BTW, you have a function called 'pigword' that has a local name also
called 'pigword'. Try not to do that, because you could easily confuse
yourself.

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