print adds a space separator between each printed argument. Pass only one string argument to print to avoid that, by joining the strings together.
If you call print only once, you need to add the newlines yourself with \n.
Remove rstrip, as it’s not needed, and would remove the \n again. So then you have this:
...
return ''.join(f"| {line:{target_length}} |\n" for line in lst)
print(instruction(12))
With the following function, you can change the instructions lines and keep the same box format:
def instructions(current_money):
# Instructions
lines = [f"You start with ${current_money}.",
"Each play costs 25 cents.",
"For each play, the slot machine will output a random three-digit number.",
"If have two similar numbers, you will earn 50 cents.",
"If have three similar numbers, you will earn $10."
]
max_width = max([len(l) for l in lines])
dashed_line = "-" * (max_width + 4) # 4 == 2 spaces + 2 pipes
out = "| {:<" + str(max_width) + "} |\n"
out = out * len(lines)
out = dashed_line + "\n" + out.format(*lines) + dashed_line
return out
def engine(current_money=10.0):
# Instruction
print(instructions(current_money))
# engine code...
engine(8)
>>>----------------------------------------------------------------------------
>>>| You start with $8. |
>>>| Each play costs 25 cents. |
>>>| For each play, the slot machine will output a random three-digit number. |
>>>| If have two similar numbers, you will earn 50 cents. |
>>>| If have three similar numbers, you will earn $10. |
>>>----------------------------------------------------------------------------