# [Tutor] calculator

Ignacio Vazquez-Abrams ignacio@openservices.net
Tue, 28 Aug 2001 13:43:36 -0400 (EDT)

```Something else you can do, in conjunction with all the other really good

---
def circlearea():
...

def squarearea():
...

def rectanglearea():
...

def squareroot():
...

...

while 1:
while 1:
print
print "1. circle area"
print "2. square area"
print "3. rectangle area"
print "4. square root"
shape = input("> ")
print
print "whoops thats not good"
print
else:
break
---

That way finding the option is a matter of a lookup in a dictionary.

If you wanted to be REALLY clever you could do the following:

---
menuoptions={'1':(circlearea, 'circle area'), '2':(squarearea, 'square area'),
'3':(rectanglearea, 'rectangle area'), '4':(squareroot, 'square root',

while 1:
while 1:
print
print "%s. %s" % (i, menuoptions[i][1])
shape = input("> ")
print
print "whoops thats not good"
print
else:
break
---

That way you get not only the valid inputs and the functions to call from the
dictionary, but also the descriptions to print in the menu. And adding new
functions is simply a matter of adding entries to the dictionary.

--
Ignacio Vazquez-Abrams  <ignacio@openservices.net>

```