Traceback (most recent call last): File "C:/Python23/calculator", line 38, in -toplevel- a.retry() File "C:/Python23/calculator", line 32, in retry Calculator.calc() TypeError: unbound method calc() must be called with Calculator instance as first argument (got nothing instead)
import sys class Calculator(object): 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: ")) if op != "a" and op != "s" and op != "m" and op != "d" and op != "end": exit = str.lower(raw_input("Are you sure you want to exit calculator (Yes or No)? ")) if exit == "yes": sys.exit(0) else: calc() else: if op == "a": print ("\nThe result is: ", x, "+", y, "=", str(x+y)) elif op == "s": print ("\nThe result is: ", x, "-", y, "=", str(x-y)) elif op == "m": print ("\nThe result is: ", x, "*", y, "=", str(x*y)) elif op == "d": print ("\nThe result is: ", x, "/", y, "=", str(float(x)/float(y))) def retry(self): confirm = str.lower(raw_input("Would you like to do another calculation (Yes or No)? ")) if confirm == "yes": Calculator.calc() else: sys.exit(0) a = Calculator() a.calc() a.retry() raw_input("\nPress any key to exit.")