Hey! I have just started a python course and Im having a hard time to put a clear button on my calculator! Thanks for helping!
This is my code:
This is my code:
import re print("First calculator") print("Type 'quit' to exit\n") previous = 0 run = True def performMath(): global run global previous equation = "" if previous == 0: equation = input("Enter equation:") else: equation = input(str(previous)) if equation == 'quit': print("Goodbye, human!") run = False else: equation = re.sub('[a-zA-Z:" "]', '', equation) if previous == 0: previous = eval(equation) else: previous = eval(str(previous) + equation) print("You typed", previous) while run: performMath()