Created
March 9, 2026 20:40
-
-
Save elyssonmr/d826777a0173af6ab29a9b491c354191 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Calculator: | |
| def __init__(self): | |
| self._history = [] | |
| @property | |
| def history(self): | |
| return self._history | |
| def _add_history_entry( | |
| self, num1: int, num2: int, operation: str, result: int | |
| ): | |
| self._history.append({ | |
| 'num1': num1, | |
| 'num2': num2, | |
| 'operation': operation, | |
| 'result': result | |
| }) | |
| def sum_numbers(self, num1: int, num2: int): | |
| result = num1 + num2 | |
| self._add_history_entry(num1, num2, '+', result) | |
| return result | |
| def subtract_number(self, num1: int, num2: int): | |
| result = num1 - num2 | |
| self._add_history_entry(num1, num2, '-', result) | |
| return result | |
| class calcu_lator(Calculator): | |
| pass | |
| calculator = Calculator() | |
| exit = False | |
| while not exit: | |
| print('Operação Soma') | |
| num1 = int(input('Operador 1: ')) | |
| num2 = int(input('Operador 2: ')) | |
| if num1 != 0 and num2 != 0: | |
| print(f'Resultado {calculator.sum_numbers(num1, num2)}\n') | |
| else: | |
| print('\Histórico de operações\n') | |
| for entry in calculator.history: | |
| num1 = entry['num1'] | |
| operation = entry['operation'] | |
| num2 = entry['num2'] | |
| result = entry['result'] | |
| print(f'{num1} {operation} {num2} = {result}') | |
| exit = True | |
| calculator2 = calcu_lator() | |
| exit = False | |
| while not exit: | |
| print('Operação Subtração') | |
| num1 = int(input('Operador 1: ')) | |
| num2 = int(input('Operador 2: ')) | |
| if num1 != 0 and num2 != 0: | |
| print(f'Resultado {calculator2.subtract_number(num1, num2)}\n') | |
| else: | |
| print('\nOperations history\n') | |
| for entry in calculator2.history: | |
| num1 = entry['num1'] | |
| operation = entry['operation'] | |
| num2 = entry['num2'] | |
| result = entry['result'] | |
| print(f'{num1} {operation} {num2} = {result}') | |
| exit = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class calcu_lator: | |
| def __init__(self): | |
| self._history = [] | |
| @property | |
| def history(self): | |
| return self._history | |
| def _add_history_entry( | |
| self, num1: int, num2: int, operation: str, result: int | |
| ): | |
| self._history.append({ | |
| 'num1': num1, | |
| 'num2': num2, | |
| 'operation': operation, | |
| 'result': result | |
| }) | |
| def sum_numbers(self, num1: int, num2: int): | |
| result = num1 + num2 | |
| self._add_history_entry(num1, num2, '+', result) | |
| return result | |
| def subtract_number(self, num1: int, num2: int): | |
| result = num1 - num2 | |
| self._add_history_entry(num1, num2, '-', result) | |
| return result | |
| calculator = Calculator() | |
| exit = False | |
| while not exit: | |
| print('Operação Soma') | |
| num1 = int(input('Operador 1: ')) | |
| num2 = int(input('Operador 2: ')) | |
| if num1 != 0 and num2 != 0: | |
| print(f'Resultado {calculator.sum_numbers(num1, num2)}\n') | |
| else: | |
| print('\Histórico de operações\n') | |
| for entry in calculator.history: | |
| num1 = entry['num1'] | |
| operation = entry['operation'] | |
| num2 = entry['num2'] | |
| result = entry['result'] | |
| print(f'{num1} {operation} {num2} = {result}') | |
| exit = True | |
| calculator2 = calcu_lator() | |
| exit = False | |
| while not exit: | |
| print('Operação Subtração') | |
| num1 = int(input('Operador 1: ')) | |
| num2 = int(input('Operador 2: ')) | |
| if num1 != 0 and num2 != 0: | |
| print(f'Resultado {calculator2.subtract_number(num1, num2)}\n') | |
| else: | |
| print('\nOperations history\n') | |
| for entry in calculator2.history: | |
| num1 = entry['num1'] | |
| operation = entry['operation'] | |
| num2 = entry['num2'] | |
| result = entry['result'] | |
| print(f'{num1} {operation} {num2} = {result}') | |
| exit = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment