Tidier Exit
[Back] <- - + - -> [Next]
Although the Exit option will often appear last in a menu
it is often slightly better to test for 'x' first.
while True:
# previous code ### The displayed menu is not changed
if option == 'x': ### Move the test for exit to the top
break ### and change it from an elif to an if
elif option == 'a': ### Change the if for 'a' to an elif
print 'You selected "a"'
# previous code
else:
print 'Invalid choice - try again'
Running the code produces this output:
:
Enter your choice: x
There is no change from
the user's point of view.
The prototype menu system is now complete.