import sys class Calculator(object): def quit_prompt(self): exit = str.lower(raw_input("Are you sure you want to exit calculator (Yes or No)? ")) if exit == "yes": sys.exit() else: calc() def add(self, x, y): print "The result is: ", x, "+", y, "=", str(x+y) def subt(self, x, y): print "The result is: ", x, "-", y, "=", str(x-y) def mult(self, x, y): print "The result is: ", x, "*", y, "=", str(x*y) def div(self, x, y): print "The result is: ", x, "/", y, "=", str(float(x)/float(y)) def calc(self): x = int(input("Please enter the first number: ")) y = int(input("Please enter the second number: ")) #op = Operator op = str.lower(raw_input( "Please enter what method you want to use ((A)ddition, (S)ubtraction, (M)ultiplication, (D)ivision) or type 'end' to quit: ")) while op != "end": if op == "a": self.add(x, y) if op == "s": self.subt(x, y) if op == "m": self.mult(x, y) if op == "d": self.div(x, y) self.retry() break def retry(self): confirm = str.lower(raw_input("\nWould you like to do another calculation (Yes or No)? ")) if confirm == "yes": self.calc() else: pass a = Calculator() a.calc() print "\nThank you for using the calculator!" raw_input("\nPress any key to exit.")