-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate_raw.py
58 lines (48 loc) · 1.46 KB
/
calculate_raw.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
import sys
if len(sys.argv) != 4:
print('Arg len should be 4')
sys.exit()
left_operand = sys.argv[1]
right_operand = sys.argv[3]
operation = sys.argv[2]
allowed_operations = ['+', '-', '/', '*', '%']
if operation not in allowed_operations:
print('Operation is not allowed')
sys.exit()
try:
left_operand = int(left_operand)
right_operand = int(right_operand)
except ValueError:
print('Left and Right operands must be int')
sys.exit()
if operation == '/' and right_operand == 0:
print('Division by zero is not allowed')
sys.exit()
# ## Option 1
match operation:
case '+':
print(left_operand + right_operand)
case '-':
print(left_operand - right_operand)
case '*':
print(left_operand * right_operand)
case '/':
print(left_operand / right_operand)
case '%':
print(left_operand % right_operand)
# Option 2
# if operation == '+':
# print(left_operand + right_operand)
# elif operation == '*':
# print(left_operand * right_operand)
# elif operation == '-':
# print(left_operand - right_operand)
# elif operation == '/' and right_operand == 0:
# print('Division by zero is not allowed')
# elif operation == '/':
# print(left_operand / right_operand)
# elif operation == '%' and right_operand == 0:
# print('Division by zero is not allowed')
# elif operation == '%':
# print(left_operand % right_operand)
# print (calculation(left_operand, right_operand, operation))