After reading some answers above, I create a function that return my string
def instruction(current_money=10.0):
return f"""
---------------------------------------------------------------------------
| You start with ${current_money:<19} |
| 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. |
---------------------------------------------------------------------------
"""
I want it to be clean as much as possible, if I turn it to a list like @mlgtechuser said before, my string will lose the first and the last line.
Testing with @mlgtechuser instruction but the string turned wrong:
def instruction(current_money=10.0):
lst = (
"------------------------------------------------------------------------",
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.",
"------------------------------------------------------------------------",
)
target_length = 72
return map(str.rstrip, (f"| {line:{target_length}} |" for line in lst))
print(*instruction(12))
will print:
| You start with $12 |
| 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. |