Scientific Computing with Python Projects - Arithmetic Formatter

Tell us what’s happening:
I am failing all 10 cases on replit, but when I run the code in pycharm, the outputs seem to match the expected output from the test cases. Also, when the fail message shows my output versus the expected output, they seem identical in about half of the cases. Can someone show me what I am doing wrong? I couldn’t figure out how to format the code correctly for the post, so I am posting a join link to the replit project. I hope that is okay.

Your code so far
https://replit.com/join/xjjafruriz-lukebowman1

Your browser information:

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

Challenge: Scientific Computing with Python Projects - Arithmetic Formatter

Link to the challenge:

-   3801      123
+   3801      123    
?                ++++
- -    2    +  49
+ -    2    +  49    
?                ++++
- ------    -----
+ ------    -----    
?                ++++

This is showing that you have extra spaces at the end of your lines

    for x in first_row_list:
        if first_row_list.index(x) == -1:
          first_row += " " * (len(third_row_list[first_row_list.index(x)]) - len(x)) + x
        else:
          first_row += " " * (len(third_row_list[first_row_list.index(x)]) - len(x)) + x + ' ' * 4
    for x in second_row_list:
      if second_row_list.index(x) == -1:
        second_row += x
      else:
        second_row += x + ' ' * 4
    for x in third_row_list:
      if third_row_list.index(x) == -1:
        third_row += x
      else:
        third_row += x + ' ' * 4
    for x in fourth_row_list:
      if fourth_row_list.index(x) == -1:
        fourth_row += " " * (len(third_row_list[fourth_row_list.index(x)]) - len(x)) + x
      else:
        fourth_row += " " * (len(third_row_list[fourth_row_list.index(x)]) - len(x)) + x + ' ' * 4

I thought by adding these “if, else” statements would stop it from adding the extra spaces on the end of the last problem in the list. Why isn’t it?

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

2 Likes

What does an index of -1 mean?

I was under the impression that it meant the last item in the list.

You can use -1 to get the last element, but the index of that element will not be -1

1 Like

sorry I was messing around with your code…

It helped actually with the spacing at the end. Thank you.

1 Like