def main(): root = make_root() display = make_display(root) label = make_label(root) buttons = make_buttons(root) calculator = Calculator(root, label, display, buttons) calculator.start()
from calculator_class import Calculator calculator_object = Calculator() a = float(input('What number would you like to convert to inches')) inches = round(calculator_object.multiply(a, 2.54), 2) print(f' {a} cm = {inches} inches (to 2 decimal places).')
from calculator_class import Calculator # import the class that handles the calculator functions c = Calculator() # create a Calculator object ans = None operators = '** * / // - +'.split() # list of available operators for use in the calculator evaluated = False """This calculator is intended to handle most expressions available on a standard calculator, while handling user errors at the same time, such as invalid expressions or zero division errors. The calculator will run until the user types "exit", and the user has the option of carrying over their answer to perform more calculations, or clearing their answer and starting over again. In addition, several blank print lines were added to enhance readability and ensure that lines are not placed too closely together.""" print('Please enter only one equation at a time. If you have a bigger equation, please consider the order of operations, then enter multiple equations.\n') while ans != 'exit': ans = input('Please enter the equation you want to evaluate, one character at a time. If you want to stop, type "exit": ').lower().strip() try: # try the below, and if it fails, move to the except blocks to catch errors. if ans == '=': result = c.equals() print(result) evaluated = True elif ans.isdecimal() or ans in operators: c.push(ans) # push the answer onto the expression, which is separated by a space in the method definition. else: