Scientific Computing with Python Projects - Arithmetic Formatter

My console is showing everything is correct, but replit is saying there are too many errors.

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0

Challenge Information:

Scientific Computing with Python Projects - Arithmetic Formatter

3 Likes

Let’s look at the errors one at a time. Here’s the first one:

____________________________________________________________________ test_template[test_two_problems_arrangement1] _____________________________________________________________________

arguments = [['3801 - 2', '123 + 49']], expected_output = '  3801      123\n-    2    +  49\n------    -----'
fail_message = 'Expected different output when calling "arithmetic_arranger()" with ["3801 - 2", "123 + 49"]'

>   ???
E   AssertionError: Expected different output when calling "arithmetic_arranger()" with ["3801 - 2", "123 + 49"]
E   assert 'Error: Too many problems.' == '  3801      123\n-    2    +  49\n------    -----'
E     + Error: Too many problems.
E     -   3801      123
E     - -    2    +  49
E     - ------    -----

/home/runner/boilerplate-arithmetic-formatter-2/test_module.py:77: AssertionError

This line:

E   assert 'Error: Too many problems.' == '  3801      123\n-    2    +  49\n------    -----'

Says your output was Error: Too many problems. but it expected this string: 3801 123\n- 2 + 49\n------ -----

This was pretty confusing because when I copied the test arguments it looks like it works:

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

but when you run the test it prints out ‘Error: Too many problems.’

However, if you look at the new loaded boilerplate and the original function call it looks like this

https://www.freecodecamp.org/learn/scientific-computing-with-python/scientific-computing-with-python-projects/arithmetic-formatter

arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"])

Your code is working for a function call that looks like this:

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

You’ve added a nested list there, but the tests don’t do that.

Put this in your main.py

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

And you will see the problem.

3 Likes

I appreciate the reply! I must have royally goofed something at some point, I added the nested lists because it was telling me my index was out of range when trying to get the boolean from the test parameters. But after doing what you said it works perfectly.

3 Likes

In the test scripts, the test arguments appear as nested lists like that. You might have copied it from there during testing, which is exactly what I did at first.

pytest.param(
        [['3801 - 2', '123 + 49']],
1 Like

You could also note that the Boolean value isn’t in the list but is a second argument.

That actually probably is what i did, definitely and easy mistake to make.