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.

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.