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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
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() |