Simple Calculator in Python Console.

Programming for fun.

Programming for fun.

Objective

To be able to perform simple operations using a Python script by writing the equations.

Introductory Statement

A calculator is something used for making mathematical calculations, in particular a small electronic device with a keyboard and a visual display. The purpose of this project is performing simple calculations on a Python console.

Results

Code

import re
print("Simple Calculator")

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")
        run = 
False
    elif 
equation == "clear":
        previous = 
0
    
else:
        equation = re.sub(
'[a-zA-Z,.:()]','',equation)

        
if previous == 0:
            previous = 
eval(equation)
        
else:
            previous = 
eval(str(previous) + equation)

while run:
    performMath()