Stumped by Arithmetic Formatter

I need help with the Arithmetic Formatter. I have tested the code outside of Replit and it seems to function as the description describes, but it keeps failing all the tests. I am not sure where I am going wrong with this. Any help would be greatly appreciated.

Here’s the link to my Replit work:

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

Challenge: Arithmetic Formatter

Link to the challenge:

Hi, I tried posting in here early, but my link doesn’t seem to show up in the previous post. I have been working on the Arithmetic Formatter and my code seems to work well when I use it in PyCharm. However, I keep failing all the tests on Replit.

Here is the link to my Replit code:

Thanks in advance for any help!

Well that’s a collection of errors right there…
So the main error is that at the end of the arranged problems, there is a symbol to much. It’s either a space or a linebreak.

Then there is something wrong with your errors. You are supposed to return a string with text. Instead you are printing a message and then calling exit().

Then we got an issue where you try to use “solution” without having created it first. This indicates pieces of your code either running or skipping vital steps unintended → and low and behold, when the operator is neither “+” nor “-” you actually keep running the code but “solution” is created in an if-elif and thus never, if the operator is wrong. So that’s also an inconsistency where you forgot to call exit(). Keep in mind, calling exit() is actually wrong, just saying.

1 Like

Thanks a lot, I redid the Errors and fixed the issue with the whitespace at the end of the lines - it was an extra newline. It passes all of the tests now, but I didn’t specifically address the issue with solution being called before it is created, so I guess it was rooted in the other problems you pointed out.

Clearly, I am still very much a novice and printing and exit() have been a bit of a crutch for me, so thank you for the clarification. I really appreciate the help.

As I said, it was code that was not meant to run - as you now return the proper message the function will terminate if the operators are wrong and thus never get to the point that would have caused the issue :wink:

1 Like

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