Help with Python Course exercise one

Hello everyone
I am trying to solve the projects of the Scientific Computing with Python course.
This is my solution for the Arithmetic Formatter link: boilerplate-arithmetic-formatter - Python Repl - Replit. I think it’s good, but the automatic tests fail and I’m not sure why because in all my test it works just fine.
If anyone can help me I will appreciate it. Thanks

Ok, let’s take a look at the failed tests

_________________________ 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 '  3801      123\n-    2    +  49\n______    _____' == '  3801      123\n-    2    +  49\n------    -----'
E         3801      123
E       -    2    +  49
E     - ------    -----
E     + ______    _____

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

The lines starting with - are the expected and the lines starting with + are your code.
Do you see the difference? You used the wrong character, you need dashes like — instead of underscores like ___

If you fix that, various tests will be fixed.

Now, an other batch.

________________________ test_template[test_two_problems_with_solutions] _________________________

arguments = [['3 + 855', '988 + 40'], True]
expected_output = '    3      988\n+ 855    +  40\n-----    -----\n  858     1028'
fail_message = 'Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with ["3 + 855", "988 + 40"] and a second argument of `True`.'

>   ???
E   TypeError: arithmetic_arranger() takes 1 positional argument but 2 were given

/home/runner/boilerplate-arithmetic-formatter/test_module.py:76: TypeError

You get a TypeError that says

arithmetic_arranger() takes 1 positional argument but 2 were given

It seems you didn’t implement a part of the instructions that says

The function should optionally take a second argument. When the second argument is set to True , the answers should be displayed.

1 Like

In the first case, it was changing the low dash for a regular dash. So that’s fixed
In the second case, I did implement that in my code. When I test it in main.py it works fine with and without True. I’m not sure why that error appears.
Thanks a lot for the help!

How is implemented? Your arithmetic_arranger function takes only one argument

so the function is ‘arithmetic_arranger(operation)’
Then I check if ‘operation’ has a True in the second argument because the problems come in this form [ ['111+ 11 ', ‘111-11’] , True]
If it doesn’t have a True in the second argument (that is [1]). It means there is no True and the function just has to deal with the operations.
Does that make sense?

No, you need a second parameter.
The function is called arithmetic_formatter(['111+ 11 ', ‘111-11’], True)

I made it. So optional argument was the solution.
Thank you very much ilenia

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