Arithmetic Formatter: Works on PyCharm but not test_module

Tell us what’s happening:
Running the test_module questions in PyCharm, my code returns the desired output every time. However, whilst running the test_module on, it returns alot of errors.

Your code so far

Your browser information:

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

Challenge: Arithmetic Formatter

Link to the challenge:

Hey, having a look at your code i spotted some things.
In your def arithemetic_arranger you have defs inside of it. I advise against it in this challenge. This is because it makes the code more convoluted and difficult to read. Also it adds additional problems. For example the Error message needs to be returned, not printed.

14 def arithmetic_arranger(formulas, condition=True):
15    def much_prob(formulas):
16        global sets,operate,over_problems,equations
17       sets=list()
18        operate=list()
19        equations=list()
20        over_problems=[]
21        if len(formulas)>5:
22>          print('Error: Too many problems.')

But even if change the print to return, this will not pass the test because it is returning it to the much_prob call below.

133    much_prob(formulas)

if you were to change these lines to fix the test you could do this:

22       return 'Error: Too many problems.'
133   x = much_prob(formulas)
134   return x

but as you can see this is adding complexity where it not needed and adding further bugs to your code.

To pass the test module use the following tips,

remove def inside the arithemetic_arranger.

For this problem you know that there is a max of 5 problems and all the problems must be on the same line. so you only need to print 4 lines max. 2 lines for numbers, 1 line for dashes, and 1 line for answers.

  34    line1
 +12   line2
-----   line3
  46    line4

So start with 4 strings, 1 for each line. append the problems by one to each line.

And to calculate the answer for a problem you can use the eval() operator in python. Google what it does and you will find it very useful for this challenge.

Hope this helps.

1 Like

Thank you so much for the detailed advice!