-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicalc.py
executable file
·71 lines (52 loc) · 1.57 KB
/
icalc.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
import calculator
import cmd
import sys
class InteractiveCalculator(cmd.Cmd):
intro = 'Welcome to the Commsignia InteractiveCalculatorPro 2022. Type help or ? to list commands.\n'
prompt = '(icalc) '
cal = calculator.Calculator()
def do_add(self, arg):
'A + B'
print(self.cal.add(*parse(arg)))
def do_sub(self, arg):
'A - B'
print(self.cal.sub(*parse(arg)))
def do_mul(self, arg):
'A * B'
print(self.cal.mul(*parse(arg)))
def do_div(self, arg):
'A / B'
print(self.cal.rem(*parse(arg)))
def do_rem(self, arg):
'A % B'
print(self.cal.div(*parse(arg)))
def do_sqrt(self, arg):
'sqrt(A)'
print(self.cal.sub(*parse(arg)))
def do_bit_and(self, arg):
'A & B'
print(self.cal.band(*parse(arg)))
def do_bit_or(self, arg):
'A | B'
self.cal.bor(*parse(arg))
def do_bit_xor(self, arg):
'A ^ B'
print(self.cal.bxor(*parse(arg)))
def do_bit_not(self, arg):
'~num'
print(self.cal.bnot(*parse(arg)))
def do_bit_shift_left(self, arg):
'num << shift'
print(self.cal.bshr(*parse(arg)))
def do_bit_shift_right(self, a):
'num >> shift'
print(self.cal.bshl(*parse(arg)))
def do_exit(self, arg):
'quits from the program'
exit()
def parse(arg):
'Convert a series of zero or more numbers to an argument tuple'
return tuple(map(int, arg.split()))
if __name__ == '__main__':
InteractiveCalculator().cmdloop()