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
def arithmetic_arranger(a):
for i in range(len(a)):
for j in a:
x = j.split(' ')
val1 = int(x[0])
val2 = int(x[2])
oper = x[1]
if oper != '+' or oper != '-':
print('invalid operand')
if not x[0].isnumeric() or x[0].isnumeric():
print('Invalid number')
continue
if oper == "-":
result = int(val1) - int(val2)
print(result)
elif oper == "+":
result = int(val1) + int(val2)
print(f'{val1} \n {oper} \n {val2}\n----\n{result}')
arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"])
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run