[Tutor] while with function
fleet@teachout.org
fleet@teachout.org
Sun Nov 17 22:54:01 2002
On Mon, 18 Nov 2002, Magnus Lycka wrote:
> At 15:09 2002-11-17 -0500, fleet@teachout.org wrote:
> >I like the concept of "while 1:" but I've had problems getting it to break
> >properly. I suspect I'm having "scope" problems.
>
> Loops and if statements don't introduce new scopes as
> { } does in C etc. You only nest scopes with nested
> functions, nested classes, methods and lambdas.
> (I.e. if you type def, class or lambda inside a class
> or function.)
I have two functions:
def add()
s_name=raw_input("Surname: ")
# several more lines of the same
y=1
while y>0:
get_list()
def get_list()
print "1. Surname: "+s_name
# several more lines of the same
# read option while loop here
I had to add "global s_name, ..., ..., etc." to add() in order to get
get_list() to display the variables. I tried moving the definition of
get_list() ahead of the add() definition; but that made no difference.
add(), of course, is called by main_menu().
Is making the add() variables global the proper solution here?
Regards,
- fleet -