Jul-25-2021, 04:12 PM
Hi all,
Here's my code
Here's my code
def arithmetic_arranger(problems,answers=False): for problem in problems: print(problem) if '+' not in problem and '-' not in problem: print("Error: Operator must be '+' or '-'.") quit() temp = problem.replace(' ','') print('temp is',temp) loc = temp.find('+') or temp.find('-') #index of operator if loc > 3: print("Error: Numbers cannot be more than four digits.") print('first one') quit() elif len(temp) - loc > 4: print('len(temp) is',len(temp)) print('loc is',loc) print("Error: Numbers cannot be more than four digits.") quit() for char in problem: if char not in ['+','-',' ']: if char.isdigit()==False: print('Numbers must only contain digits.') quit() if len(problems)>5: print('Error: Too many problems.') quit() return type(problems)Second time through, after printing '3801-2', it prints 'loc is -1.' Why does line 9 not identify this as 4?