Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin2!goblin.stu.neva.ru!newsfeed1.swip.net!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: 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; 'true,': 0.05; 'assignment': 0.07; 'sys': 0.07; '22,': 0.09; 'prefix': 0.09; 'referenced': 0.09; 'sentence': 0.09; 'def': 0.12; 'random': 0.14; 'confuse': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'line)': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'stem': 0.16; 'exception': 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; 'math': 0.24; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'function': 0.29; "doesn't": 0.30; 'statement': 0.30; '25,': 0.31; '>>>>': 0.31; 'yourself.': 0.31; 'file': 0.32; '(most': 0.33; 'could': 0.34; 'test': 0.35; 'easily': 0.37; 'to:addr:python- list': 0.38; 'that,': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'skip:u 10': 0.60; 'break': 0.61; 'first': 0.61; 'name': 0.63; 'therefore': 0.72; 'subject:This': 0.74; 'subject:interesting': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=Uv7tNoAB c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=u9EReRu7m0cA:10 a=fmrOnJK_v7MA:10 a=fIYvK4aQMKUA:10 a=ihvODaAuJD4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=JPg9gMiZ0eX2RiSahh4A:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett:2500 Date: Sun, 31 Aug 2014 22:53:01 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: This could be an interesting error References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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: 1409521984 news.xs4all.nl 2864 [2001:888:2000:d::a6]:47385 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77362 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 > > 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.