Search code examples
pythonpython-3.xcommand-linereplit

python script run perfectly in command line but failed test on repl,it


enter image description here

this code run on my command line, total of 6 test and it failed two.it looks like extra space and i cant figure out how to solve it.

here is the link to my repl https://repl.it/@seunlaww/SnivelingWateryArchives-1#arithmetic_arranger.py


Solution

  • Two issues:

    • On line 2, remove an extra space
    • In the length check, use len(problems), not len(problem)

    Here is the updated code:

    line1 += num1.rjust(space)
            line2 += op + num2.rjust(space-1)  # remove extra space
            line3 += "-" * space
            line4 += str(result).rjust(space)
            if z < len(problems) - 1:   # use problems, not problem
                line1 += extra_space
                line2 += extra_space
                line3 += extra_space
                line4 += extra_space
    

    All the tests pass with these changes.