import string def Add (N1,N2): return float(N1) + float(N2) def Subtract (N1,N2): return float(N1) - float(N2) def Multiply (N1,N2): try: Result = float(N1) * float(N2) except: print "Multiplication overflow" Result = 0.0 return Result def Divide1 (N1,N2): if (N2 == 0): print "Divide by Zero error" Result = 0.0 else: Result = float(N1) / float(N2) return Result def Divide (N1,N2): try: Result = float(N1) / float(N2) except: print "Divide by Zero error" Result = 0.0 return Result def SquareRoot (N): try: Result = math.sqrt(N) except: print "Square root error" Result = 0.0 return Result def Main(): Accumulator = 0.0 MoreToDo = True while MoreToDo: Command = raw_input(str(Accumulator) + " Enter a command --- ") Command = string.lower(Command) if (Command == "quit"): MoreToDo = False elif (Command == "add") or (Command == "+"): Accumulator = Add(Accumulator, input("Enter new number --- ")) elif (Command == "subtract") or (Command == "-"): Accumulator = Subtract(Accumulator, input("Enter new number --- ")) elif (Command == "multiply") or (Command == "*"): Accumulator = Multiply(Accumulator, input("Enter new number --- ")) elif (Command == "divide") or (Command == "/"): Accumulator = Divide(Accumulator, input("Enter new number --- ")) elif (Command == "clear"): Accumulator = 0.0 elif (Command == "negate"): Accumulator = -Accumulator elif (Command == "squareroot"): Accumulator = SquareRoot(Accumulator) else: print "Illegal Command" return