GreatRaymondo

supercalc

Jun 26th, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. import re
  2.  
  3. print("Johnnys SuperCal")
  4. print("Type quit to exit\n")
  5.  
  6. previous = 0
  7. run = True
  8.  
  9. def performMath():
  10. global run
  11. global previous
  12. equation = ""
  13. if previous == 0:
  14. equation = input("Enter equation:")
  15. else:
  16. equation = input(str(previous))
  17.  
  18. if equation == "quit":
  19. print("Adios human!")
  20. run = False
  21. else:
  22. equation = re.sub('[a-zA-Z,.:()" "]', '', equation)
  23.  
  24. if previous == 0:
  25. previous = eval(equation)
  26. else:
  27. previous = eval(str(previous) + equation)
  28.  
  29. while run:
  30. performMath()
Add Comment
Please, Sign In to add comment