unerwartete Ausführung von Ausnahmen in Python
Ich bin ein Anfänger in Python und habe mir dieses Problem ausgedacht. Ich habe ein einfaches Programm für Taschenrechner gemacht. In der Add-Funktion habe ich try- except verwendet. Wenn diese Zeile angetroffen wird (wenn decision == 'no' oder decision == 'n' :), zeigt sie die Druckzeile "return (" You have exited ")" an, löst aber auch die Ausnahme aus. Ich kann nicht verstehen warum.
import sys
def menu():
print "calculator using functions"
print "Choose your option:"
print " "
print "1) Addition"
print "2) Subtraction"
print "3) Multiplication"
print "4) Division"
print "5) Quit calculator.py"
print " "
return input ("Choose your option: ")
def add(a,b):
try:
print a, "+", b, "=", a + b
print " Do you want to continue: "
decide=raw_input("yes or no: ")
if decide== 'no' or decide== 'n':
return(" You have exited ")
sys.exit(0)
elif decide=='yes' or decide== 'y':
menu()
untrusted.execute()
except:
print "wrong choice!!!"
e = sys.exc_info()[0]
print "Error: %s" % e
sys.exit(0)