Hello,
I am new to Python and am working on a project to build a calculator. I am using Pycharm to build this. Eval does not work in the code for the calculator, however, if I do a simple eval statement like x = 1 and print(eval('x + 1')) it works. Any idea why? Here is code:
Figured it out...I had print(equation) not print(previous) DUH!
I am new to Python and am working on a project to build a calculator. I am using Pycharm to build this. Eval does not work in the code for the calculator, however, if I do a simple eval statement like x = 1 and print(eval('x + 1')) it works. Any idea why? Here is code:
import re print("Our Magic Calculator") print("Type 'quit' to exit\n") previous = 0 run = True def performMath(): global run global previous equation = input("Enter equation:") if equation == 'quit': run = False else: previous = eval(equation) print(equation) while run: performMath()
Figured it out...I had print(equation) not print(previous) DUH!