# [Tutor] When I run this code, it just keeps repeating.

Nathan Pinno falcon3166 at hotmail.com
Sun Jul 31 03:55:02 CEST 2005

```When I run the following code it just keeps repeating. Here is a screen shot showing what I mean:
Mini Calculator
By Nathan Pinno

2) Subraction
3) Multiplication
4) Division w/o remainder
5) Division with remaider
6) Exponation
7) Square roots
9) Exit
Option: 5
First number:4
Second number:2
4 / 2 =  2  R  0
First number:3
Second number:6
3 / 6 =  0  R  3
First number:5
Second number:6
5 / 6 =  0  R  5
First number:

Here is the relevant code:
# This is a small calculator.
print "2) Subraction"
print "3) Multiplication"
print "4) Division w/o remainder"
print "5) Division with remaider"
print "6) Exponation"
print "7) Square roots"
print "9) Exit"

def cal():
global cal_opt
cal_opt = int(raw_input("Option: "))

print "Mini Calculator"
print "By Nathan Pinno"
print
cal()
while cal_opt != 9:
if cal_opt == 1:
X = input("First number:" )
Y = input("Second number:" )
print X, "+", Y, "= ",X + Y
elif cal_opt == 2:
X = input("First number:" )
Y = input("Second number:" )
print X, "-", Y, "= ",X - Y
elif cal_opt == 3:
X = input("First number:" )
Y = input("Second number:" )
print X, "*", Y, "= ",X * Y
elif cal_opt == 4:
X = input("First number:" )
Y = input("Second number:" )
if Y == 0:
print "Division by zero ot allowed!"
Y = input("Second number:" )
else:
print X, "/", Y, "= ",X / Y
elif cal_opt == 5:
X = input("First number:" )
Y = input("Second number:" )
if Y == 0:
print "Division by zero ot allowed!"
Y = input("Second number:" )
else:
print X, "/", Y, "= ",X / Y," R ", X % Y
elif cal_opt == 6:
X = input("First number:" )
Y = input("Power:" )
print X, "**", Y, "= ",X**Y
elif cal_opt == 7:
X = input("Number to find the square root of:" )
print "The square root of", X, " = ",X**0.5
else:
print "That's not an option. Try again."
cal()
print "Goodbye"

How do I stop this, and make it go back to the main menu?