PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#Describe a Calculator class that will implement the following methods and fields:
# sum (self, a, b) - addition of numbers a and b
# sub (self, a, b) - subtraction
# mul (self, a, b) - multiplication
# div (self, a, b, mod = False) - division. If mod == True, then the method should return the remainder of division instead of division. By default mod = False.
# history (self, n) - this method should return a string with the operation by its number relative to the current moment (1 - last, 2 - penultimate). Output format: sum (5, 15) == 20
# last - a string of the same format as in the previous paragraph, which contains information about the last operation for all created calculator objects. Those. this is the last operation of the last used calculator object. If there have been no operations yet, then None.
# clear (cls) is a method that clears last, i.e. sets it to None.
# Output format
# When storing strings in history and last, only one decimal place needs to be printed. When doing division with mod, the mod parameter itself does not need to be logged.
#p.s. The last two lines for passing tests
class Calculator:
last = None
def __init__(self):
self.history_array = []
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run