-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpreter.py
49 lines (36 loc) · 943 Bytes
/
interpreter.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
from numpy import vsplit
def multiply(x,z):
return x * z
def subtract(x,z):
return x - z
def divide(x,z):
if z == 0:
return "ERROR: cannot divide by zero"
else:
return float(x/z)
def add(x,z):
return x + z
while True:
print("Expression: ", end = '')
inp = input("").strip()
try:
x,y,z = inp.split()
except ValueError:
print("Enter something man")
if x != None and z != None:
if y == '+':
print("{:.1f}".format(add(int(x),int(z))))
break
elif y == 'x' or y == '.' or y == '*':
print("{:.1f}".format(multiply(int(x),int(z))))
break
elif y == '/':
print("{:.1f}".format(divide(int(x),int(z))))
break
elif y == '-':
print("{:.1f}".format(subtract(int(x),int(z))))
break
else:
continue
else:
quit()