I suspect that these conditions are your issue. You need to have elif (condition1) or (condition2):, where condition1 and condition2 are full logical conditions.
elif (problems) != int:
return "Error: Numbers must only contain digits."
elif (problems) == "*" or (problems) == "/":
return "Error: Operator must be '+' or '-'."
elif len(problems) > 4:
return "Error: Numbers cannot be more than four digits."
Actually, there is very little happening in your code…
Your first statement:
if len(problems) > 5:
This is correct.
Now, for the rest, I suggest you delete all of the rest of the function code, and add this: print(problems)
From there, you will be able to see:
When would problems ever be equal to "*" or "/"?
What does (problems) != int mean?
If len(problems) > 5 makes sense, as it tells you the number of problems, hows does len(problems) > 4 make sense, if it also checks the number of digits?
Finally, you are returning arranged_problems, but have not defined what that is…
Helpful, thank you! I switched to nested loops, but still not passing all tests:
def arithmetic_arranger(problems, answer=False):
if len(problems) > 5:
return "Error: Too many problems."
for i in problems:
if i == '*' or '/':
return "Error: Operator must be '+' or '-'."
for j in problems(len - 1):
if j != int:
return "Error: Numbers must only contain digits."
elif len(j) > 4:
return "Error: Numbers cannot be more than four digits."
arranged_problems = problems[i] + "\n" + problems[i, j].rjust + problems[i, j].str(" ") + problems[j][:-4]
return arranged_problems
print(arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"], True))
Can you not see any errors in the console? You have not defined a whole heap of variables you are using.
This is not doing what you expect: if i == '*' or '/': len does not exist: for j in problems(len - 1): int is a class declaration variable not something to compare against: if j != int: i and j are not defined: problems[i] + "\n" + problems[i, j].rjust + problems[i, j].str(" ") + problems[j][:-4]
These are basic issues that should be brought up in the console, when you run the script. It is a very useful skill getting to know the console, and understanding its output.