Re: Newbie Nested Function Problem

From: Rich Krauter (rmkrauter_at_yahoo.com)
Date: 01/25/04


Date: Sat, 24 Jan 2004 23:18:21 -0500
To: Brian Samek <zensunni@rochester.rr.com>

I should have suggested a 'fix' before: change all the "leave"s which
are referring to, or defining the function "leave" to "leaver" or
something like that. Keep all program's references to the variable
"leave" unchanged. Then your program should work.

To clarify my previous reply, your problem is this:

leave = 'xqz'
leave()

The leave() call is actually trying to call a string object, which is
not callable.
So I wasn't quite right in what I told you in the previous post - the
leave() call is not trying to call the function xqz(), its trying to
call the string xqz.

Rich

On Sat, 2004-01-24 at 22:47, Brian Samek wrote:

> > Okay, ask_number doesn't do what you're saying. It's asking for a number,
> > placed into variable number, and if it gets something out of range, prints
> > an error message.
> >
> > And then ends. It doesn't either a) repeat until it gets a valid number
> > or b) do anything with the number it gets, like pass it back to the caller
> > in a return statement, i.e.:
> >
>
> It does repeat if it doesn't get a valid number. The function calls itself
> after printing an error mesage. For some reason the original message
> formatted itself differently when I pasted it into my mail program. The
> line just before the first else statement should be indented to the same
> level as the line before it so it reads:
>
> def ask_number():
> number = input("Please enter a number.\n")
> if number > 500 or number - int(number) != 0 or number < 1:
> print "Input positive integers less then 501 only, please."
> ask_number()
> else:
>
>
>
> > return number
> >
> > > ask_number()
> >
> > Okay, you invoked ask_number, but didn't even try to get anything from it.
> > Normally, this would read something like:
> >
> > number_in = asknumber()
> >
>
> What do you mean by I "didn't even try to get anything from it." I get a
> variable called "number" from it from which the countdown(number) function
> counts down.
>
> > > else:
> >
> > Um.. it looks like you're inadvertably making this a deeply recursive
> > call, probably something you want to stay away from until you have regular
> > stuff down pat.
>
> I don't understand what you're saying. I designed the program as three
> functions nested within each other. Are you saying I should be designing it
> differently? I made it a series of nested functions because, for example, I
> needed to use the "number" variable from ask_number before it was destroyed.
> When a function ends, any variables it has created are destroyed.
>
> Thanks,
>
> Brian
>



Relevant Pages

  • Re: Help with Chinese character
    ... understand the word I'm saying, even though, I'm saying it ... not buy large amounts and instead stick to small tuos or loose tea. ... then lunched into another rousing bout of pete and repeat with me. ... characters and hear a woman pronounce them. ...
    (rec.food.drink.tea)
  • Re: Help with Chinese character
    ... understand the word I'm saying, even though, I'm saying it ... not buy large amounts and instead stick to small tuos or loose tea. ... then lunched into another rousing bout of pete and repeat with me. ... characters and hear a woman pronounce them. ...
    (rec.food.drink.tea)
  • Re: WBEM
    ... Well today when I started I got an error message saying ... And I am sure that I saw a log entry in the WBEM logs ... through hoops to do it. ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Adalian Says It - "Less Is More"  [Kind of WQ-Like, Isnt It?]
    ... he's really saying is less channels, ... could repeat that most viewers will be too young to remember. ... Since channels do run old TV series, ...
    (rec.arts.tv)
  • Re: IE6 problem - MSVCRT.DLL
    ... > I have a problem accessing webpages using IE6. ... > Sometimes,all of sudden I will get an error message ... > saying: that this program has performed an illegal action ... > annoying as I cannot access webpages I normally could. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)