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


Groups > comp.lang.python > #101608

Re: local variable 'juveniles' referenced before assignment

Newsgroups comp.lang.python
Date 2016-01-13 04:54 -0800
References <d668ec4e-509e-48a4-9be5-017077629c6c@googlegroups.com> <mailman.99.1452688353.13488.python-list@python.org>
Message-ID <5b66e2de-bc73-4200-a9c1-645d2e3f0467@googlegroups.com> (permalink)
Subject Re: local variable 'juveniles' referenced before assignment
From Alan Robinson <arobinson@lordlawson.org.uk>

Show all headers | View raw


On Wednesday, 13 January 2016 12:32:51 UTC, Chris Angelico  wrote:
> On Wed, Jan 13, 2016 at 11:23 PM, Alan Robinson
> <arobinson@lordlawson.org.uk> wrote:
> > def menu():
> >     option = int(input("Please select an option: \n 1: Set Generation 0 Values \n 2: View Generation 0 Values \n 3: Run Model \n 4: Print values"))
> >
> >     if option == 1:
> >         juveniles,adults,seniles = setGen()
> >     elif option == 2:
> >         displayGen()
> >     elif option == 3:
> >         runModel(juveniles,adults,seniles)
> >     elif option == 4:
> >         print(juveniles,adults,seniles)
> >     menu()
> >
> 
> This is a classic use of recursion instead of iteration. When you call
> menu() again, you're creating a completely new 'slot' for the new
> function; it has its own set of names. Assigning to names in one call
> of menu() has no effect on any other call.
> 
> Instead, look into the way a while loop works. You'll find that your
> code is simpler and clearer, plus your variables will stay set.
> 
> ChrisA
thanks I need the menu to run again not sure how to do that though

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


Thread

local variable 'juveniles' referenced before assignment Alan Robinson <arobinson@lordlawson.org.uk> - 2016-01-13 04:23 -0800
  Re: local variable 'juveniles' referenced before assignment Chris Angelico <rosuav@gmail.com> - 2016-01-13 23:32 +1100
    Re: local variable 'juveniles' referenced before assignment Alan Robinson <arobinson@lordlawson.org.uk> - 2016-01-13 04:54 -0800
      Re: local variable 'juveniles' referenced before assignment Chris Angelico <rosuav@gmail.com> - 2016-01-14 00:05 +1100
      Re: local variable 'juveniles' referenced before assignment Peter Otten <__peter__@web.de> - 2016-01-13 14:05 +0100
        Re: local variable 'juveniles' referenced before assignment Alan Robinson <arobinson@lordlawson.org.uk> - 2016-01-13 05:22 -0800
          Re: local variable 'juveniles' referenced before assignment Alan Robinson <arobinson@lordlawson.org.uk> - 2016-01-13 05:26 -0800

csiph-web