Menu Interface Problem.
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Tue Mar 10 09:11:34 EDT 2009
En Tue, 10 Mar 2009 03:48:07 -0200, Paulo Repreza <pxrepreza at gmail.com>
escribió:
> # Program exits until 'menu_item = 9'
> while menu_item != 9:
> print '-----------------'
> print '1. Print the list.'
> print '2. Add a name to the list.'
> print '3. Remove a name from the list.'
> print '4. Change an item in the list.'
> print '9. Quit'
> menu_item = input('Pick an item from the menu: ')
>
> # TO-DO for option '1'.
> if menu_item == 1:
input() is rather confusing (and is gone in Python 3). It does two things:
- retrieve some text typed by the user
- evaluate it as if it were an expresion
That means that typing 1+2 works (and will choose option 3), but typing f
will raise an exception (there is no "f" variable). I suggest you forget
about input and use raw_input instead:
menu_item = raw_input('Pick an item from the menu: ')
This returns a string (like '1'). So change all your "if" statements
accordingly:
# TO-DO for option '1'.
if menu_item == '1':
--
Gabriel Genellina
More information about the Python-list
mailing list