Scientific Computing with Python Projects - Arithmetic Formatter

Tell us what’s happening:

Hello, I can’t find why it can not meet the requirement.

Your code so far

def arithmetic_arranger(problems, show_answers=False):
    a = len(problems)
    if a > 5:
        return('Error: Too many problems.') 
    number1 = []
    number2 = []
    signe = []
    final_message = '  '
    for i in problems:
        number1.append(i.split(" ")[0])
        signe.append(i.split(" ")[1])
        number2.append(i.split(" ")[2])
    
    for i, b in enumerate(number1):
        if i < a-1 :
            final_message += b + '      '
        else:
            final_message += b + '\n'
    for i, (c, d) in enumerate(zip(signe, number2)):
        
        if i < a-1 :
            final_message += c + '    '+ d + '      '
        else:
            final_message += c + '    '+ d + '\n'
    for i in range(0, a):
        if i < a-1 :
            final_message += '------' + '    '
        else:
            final_message += '-----'

    return final_message

print(repr(arithmetic_arranger(["3801 - 2", "123 + 49"])))


print(arithmetic_arranger(["3801 - 2", "123 + 49"]))



Your browser information:

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

Challenge Information:

Scientific Computing with Python Projects - Arithmetic Formatter

add this to compare your code with the expected code, you will see that you have too many spaces in the middle

print('actual')
print(repr(arithmetic_arranger(["3801 - 2", "123 + 49"])))
print('expected')
print(repr("  3801      123\n-    2    +  49\n------    -----"))
print(f'actual\n{(arithmetic_arranger(["3801 - 2", "123 + 49"]))}')
print("expected\n  3801      123\n-    2    +  49\n------    -----")
1 Like

Thank you so much! It can work now. It was just a problem of space.

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