Arithmetic Formatter problem =(

Tell us what’s happening:

Hello!! I’ve been doing the first project but I’m stuck. I would like to know if my code is correct so far, and also an idea of how to do the last part of the assignment.
Thanks in advance!!!

Your code so far

def arithmetic_arranger(problems, b):
if len(problems) > 5:
return “”“Error: Too many problems.”""

elif b == False or b == None:
    pass

for number in problems:
    s = str(number)
    if ("*" or "/") in s:
        return "Error: Operator must be '+' or '-'."
    elif (number.isalpha()) == True:
        return "Error: Numbers must only contain digits."
    else:
        pass

for i, problem in enumerate(problems):
    num1, op, num2 = problem.split()
    if len(num1) > 4 or len(num2) > 4:
        return "Error: Numbers cannot be more than four digits."
    else:
        pass
    
else:
    for number in problems:
        result = eval(number)
        print (number, '----', result)

return arranged_problems #This is where I’m stuck. I don’t know how to make the columns and the indentation between them

print(‘First:’, test_1([“32 + 8”, “1 - 3801”, “9999 + 9999”, “523 - 49”], True))
print(‘Second:’,test_1([“32 + 8”, “1 - 3801”, “9999 + 9999”, “523 - 49”, “1 - 2”, “3 + 5”], False)) #too many operations, just up to 5
print(‘Third:’,test_1([“32 + 8”, “1 - 3801”, “9999 + 9999”, “523 - 49”, “9 * 1”], True)) #only ‘+’ or ‘-’. NOT ‘*’ or ‘/’
print(‘Fourth:’, test_1([“32 + 8”, “1 - 3801”, “9999 + 9999”, “abc”], True)) #only digits can appear
print(‘Fifth:’, test_1([“32 + 8”, “1 - 3801”, “9999 + 9999”, “85000 - 54000”], True)) #numbers should not have more than 4 units

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36.

Challenge: Arithmetic Formatter

Link to the challenge:

Can you check the formatting of your post?
Only half your code is formatted as code, which makes reading it a lot harder.

The last assignment, meaning creating the output string with the formatted calculations?
Well that string has a couple conditions and basically 3-4 lines of text.
So you need to write some code that checks those conditions and create a string accordingly.
My propably somewhat messy solution uses 4 for-loops, to create each line of the output string, followed by an “\n” for new-line.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.