Here is the code:
def arithmetic_arranger(problems):
#OK for first condition , length
if len(problems)>5:
print(“Error: Too many problems.”)
Spliting items
for cc in problems:
it=cc.split()
fi=it[0]
se=it[1]
th=it[2]
#print(fi)
### 4 digits and cant be more than 4
if len(fi)>4 or len(th)>4:
print('Error: Numbers cannot be more than four digits.')
if not fi.isnumeric() or not th.isnumeric():
print('Error: Numbers must only contain digits.')
if se == '+' or se == '-':
print('Error: Operator must be '+' or '-'.')
#arithmetic_arranger([‘1 + 22’])
arithmetic_arranger([‘33 2 22’,‘3 4 5’,‘55 - 5’])
Error message:
Traceback (most recent call last):
File “C:\Users\nrky1\Desktop\python new\ass1.py”, line 31, in
arithmetic_arranger([‘33 2 22’,‘3 4 5’,‘55 - 5’])
File “C:\Users\nrky1\Desktop\python new\ass1.py”, line 21, in arithmetic_arranger
print(‘Error: Operator must be ‘+’ or ‘-’.’)
TypeError: unsupported operand type(s) for -: ‘str’ and ‘str’
I don’t quite understand why I would get this message as the elements in the list are strings.
Link to the problem set: