[Tutor] calculator
Andrei Kulakov
ak@silmarill.org
Tue, 28 Aug 2001 13:51:35 -0400
On Tue, Aug 28, 2001 at 01:43:36PM -0400, Ignacio Vazquez-Abrams wrote:
> Something else you can do, in conjunction with all the other really good
> suggestions you've received so far, is to code your main menu (and in fact all
> of your menus) similar to this:
>
> ---
> def circlearea():
> ...
>
> def squarearea():
> ...
>
> def rectanglearea():
> ...
>
> def squareroot():
> ...
>
> def addnumbers():
> ...
>
> menuoptions={'1':circlearea, '2':squarearea, '3':rectanglearea,
> '4':squareroot, '5':addnumbers}
>
> while 1:
> while 1:
> print "please choose an option"
> print
> print "1. circle area"
> print "2. square area"
> print "3. rectangle area"
> print "4. square root"
> print "5. add numbers"
> shape = input("> ")
> if not menuoptions.has_key(shape)
> print
> print "whoops thats not good"
> print
> else:
> break
> menuoptions[choice]()
Is it just me, or are alphanumeric menus much nicer, i.e.:
menu = {
'c': circlearea,
'a': squarearea,
'r': rectanglearea,
'o': squareroot,
'a': addnumbers
}
And that letter is colorized in the menu? This is very easy
to do and much friendlier UI - gtk and qt, take a hike ;P.
[snip]
--
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org