Created
December 6, 2022 18:38
-
-
Save bDrwx/d0c40efe8027ef62b9dbc0faa7fc95dd to your computer and use it in GitHub Desktop.
This file contains 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
from typing import Optional | |
class Digit: | |
def __init__(self, val: int, acc: Optional[str] = None): | |
self.val = val | |
self.acc = acc | |
def set_val(self, val): | |
self.val = val | |
def set_acc(self, acc): | |
print(f'acc is set {acc}') | |
self.acc = acc | |
def eval(self, a: int): | |
print(f'{a}{self.acc}{self.val}') | |
self.val = eval(f'{a}{self.acc}{self.val}') | |
self.acc = None | |
def __str__(self) -> str: | |
return str(self.val) | |
def one(a: Optional[Digit] = None) -> Digit: | |
if type(a) is Digit: | |
a.eval(1) | |
return a | |
else: | |
return Digit(1) | |
def two(a: Optional[Digit] = None) -> Digit: | |
if type(a) is Digit: | |
a.eval(2) | |
return a | |
else: | |
return Digit(2) | |
def three(a: Optional[Digit] = None) -> Digit: | |
if type(a) is Digit: | |
a.eval(3) | |
return a | |
else: | |
return Digit(3) | |
def four(a: Optional[Digit] = None) -> Digit: | |
if type(a) is Digit: | |
a.eval(4) | |
return a | |
else: | |
return Digit(4) | |
def five(a: Optional[Digit] = None) -> Digit: | |
if type(a) is Digit: | |
a.eval(5) | |
return a | |
else: | |
return Digit(5) | |
def plus(a: Digit) -> Digit: | |
a.set_acc('+') | |
return a | |
def minus(a: Digit) -> Digit: | |
a.set_acc('-') | |
return a | |
def mult(a: Digit) -> Digit: | |
a.set_acc('*') | |
return a | |
def div(a: Digit) -> Digit: | |
a.set_acc('/') | |
return a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment