Newbia alert .. working my way through Easy Python Montana Edu page, need help..
aleax at aleax.it
Fri Sep 20 10:01:54 EDT 2002
> def print_options() :
You define this function, but never call it anywhere.
> choice = 'p'
> while choice != 'q':
> if choice == 'r':
> a=input ("width")
> b=input ("height")
> print "result",rect (width,height)
Note that the print is NOT aligned with the input calls, but
rather with the if statement. Thus, the print (and its call
to rect) is not conditional -- it happens even when choice
is NOT 'r'. This is unlikely to be what you want, so, indent
this print statement 4 more spaces rightwards.
However, the crux of your problem is another:
> But the thing keeps telling me width is not defined, also I can;t use
Inddeed, width is not a defined variable: what you obtained
from the call to input("width") you did not assign to the
name width, but rather to the name a. Therefore, the variable
that is defined once this statement has executed is named a.
Therefore, change your call to rect to rect(a,b) -- and
similarly for the following passages in your code.
> the ELIF command .. THink I could do with some help :)
The reason you can't use elif (not a 'command' -- a clause
in an if statement) is probably the indentation problem I
mentioned earlier -- once you fix that you can probably
also change the following if's to elif's (not the first one
of course). When indentation returns to the same level as
the word 'if', it means the if statement is over: therefore
you cannot "reprise" it later, continuing it, so to speak,
with an elif clause. Once you correct the indentation of
the print statements, this will change.
More information about the Python-list