[Tutor] Defining functions
Alan Gauld
alan.gauld at freenet.co.uk
Fri Mar 25 10:07:45 CET 2005
> If I try to change the 1, 2, 3, 4 or 5 by a letter i.e. a, b, c, d,
e the
> programme stop functionning. I get an error message saying that
>
> Traceback (most recent call last):
> File "C:/Python24/Example/area_cir_squ_regt.py", line 39,
in -toplevel-
> print_options()
> File "C:/Python24/Example/area_cir_squ_regt.py", line 27, in
print_options
> choice = input("Choose an option: ")
> File "<string>", line 0, in -toplevel-
> NameError: name 'c' is not defined
>
> What am I missing? Thanks
Some quote signs...
You need to use raw_input().
input tries to evaluate what the user types, so if they type c, input
looks for a variable called c and tries to return its value. But
you don't have a variable called c.... and if you had, things would
be even more confusing!
Using input is useful occasionally but potentially dangerous because
a malicious user could type python code into your program and break
it.
Use raw_input() instead and convert the result as you need it (using
int(),
float(), str(), or whatever...).
Alan G.
More information about the Tutor
mailing list