Having issue with Arithmetic Formatter test

I’m currently working on the first Python project “Arithmetic Formatter” under the Scientific Computing with Python Projects. One of the starting tests is giving me issue “test_module.py::test_template[test_incorrect_operator] FAILED”. I tried using regex and for in loop with if statement. I keep failing “Error: Operator must be ‘+’ or ‘-’.”. Is it possible to use list comprehension or must I split each individual index after looping argument from function. To search for test values ?. As I saw in other coders questions on this forum ?.
Here is my current version of my project. My Arithmetic Formatter Link
Any help is appreciated.

Relevant code

for character in  problems:
    
     if character in problems != '-' or character in problems != '+': 
         return  "Error: Operator must be '+' or '-'."
     

Have you checked if the individual parts of the if statement are what you expect? Try looking at that, ie:

print(character)
print(character in problems)
print(character in problems != '-')

Sorry I took so long to reply. I finally went with regular expression. Which I got to work with test parameters. My previous code had an error that I should have use and instead of or. To make both conditional statements to be true to pass in if statement example:
if character in problems != ‘-’ or character in problems != ‘+’:
Should have been if character in problems != ‘-’ and character in problems != ‘+’:
I found regular expressions works better for me.
Here is my current code:
Current Arithmetic Formatter

It’s purely coincidental if if character in problems != ‘-’ and character in problems != ‘+’: gave correct result for some cases.

I’d still suggest to take a look what each part of that statement is evaluated to.

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