Tell us what’s happening:
I am not sure how to correct some of the errors that are occurring. For example, I am checking for length, operator, and trying ensure the string is a number but I am not able to pass the tests. What is wrong with my code so far? I am pretty new to Python so not sure I fully understand what else I should try to do in order to get some of the code blocks to pass.
I understand why I am getting formatting errors. My plan is to check for Errors first with the input then define arrange_problems so the programs output is the arranged and formatted problem.
Here is a link to my Repl.
Your code so far
def arithmetic_arranger(problems): if len(problems) > 5: return("Error: Too many problems.") #splits problems for p in problems: prob = p.split(' ') num1 = prob operand = prob num2 = prob #block to check for length, operator, and digits if not len(num1) < 4 or not len(num2) < 4: return("Error: Numbers must not be longer than 4 digits.") if not operand == '+' or not operand == '-': return("Error: Operator must be '+' or '-'.") if not num1.isnumeric() or not num2.isnumeric(): return("Error: Numbers must only contain digits.") else: pass
Your browser information:
User Agent is:
Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36.
Challenge: Arithmetic Formatter
Link to the challenge: