<html>
<body>
At 06:55 PM 7/30/2005, Nathan Pinno wrote:<br>
<blockquote type=cite class=cite cite="">...<br>
elif cal_opt == 4:<br>
X = input("First
number:" )<br>
Y = input("Second
number:" )<br>
if Y == 0:<br>
print
"Division by zero ot allowed!"<br>
Y =
input("Second number:" )<br>
else:<br>
print
X, "/", Y, "= ",X / Y</blockquote><br>
Note that you give user a 2nd try but that input never reaches the print
statement.<br><br>
The following might be a bit of a stretch, but consider creating a list
of lists to store the various menu options. <br>
Doing this separates the high-level menu from lower-level code which is
now not repetitive. To add/modify menu items one just extends/edits the
list. Here's a "simple" example which ignores some things but
gives you the idea. Warning untested code:<br><br>
menuItems = [<br>
["Add", "First number:", "Second
number:", "+", lambda(x,y:x+y)],<br>
["Subtract", "First number:", "Second
number:", "-", lambda(x,y:x-y)],<br>
["Exit"]]<br>
# first item is the main menu prompt, <br>
# 2nd and 3rd are the input prompts, <br>
# 4th is the string representation of the operator, <br>
# 5th is an anonymous function to do the calculation.<br><br>
def menu():<br>
print "CALCULATE MENU"<br>
for option, menuItem in enumerate(menuItems):<br>
print str(option + 1) + ")",
menuItem[0]<br><br>
def cal():<br>
cal_opt = int(raw_input("Option: "))<br>
if 1 <= cal_opt <= len(menuItems):<br>
menuItem = menuItems[cal_opt - 1]<br>
if menuItem[0] = "Exit":return False<br>
prompt1, prompt2, oper, func =
menuItem[1:]<br>
X = input(prompt1)<br>
Y = input(prompt2)<br>
print X, oper, Y, "= ", func(X, Y)<br>
else:<br>
print "That's not an option. Try
again."<br>
return True<br><br>
print "Mini Calculator"<br>
print "By Nathan Pinno"<br>
print<br>
while True:<br>
menu()<br>
if not cal(): break<br>
<x-sigsep><p></x-sigsep>
<font size=2>Bob Gailer<br>
phone 510 978 4454 </font></body>
</html>