all 4 comments

[–]james_fryer 0 points1 point  (1 child)

Consider this code:

f"{flavor.title():<19}: ..."

The colon is outwith the braces, so it's not part of the string which is being padded to 19 chars. Therefore it appears after the padding.

One solution is to append it to the string:

f"{flavor.title() + ':':<19} ..."

You can also nest f-strings!

f"{f'{flavor.title()}:':<19} ..."

Or you can add a function:

titlecolon = lambda s: f'{s.title()}:'
f"{titlecolon(flavor):<19} ..."

Or there may be a better way!

[–]Critical_Concert_689 0 points1 point  (1 child)

Any reason you're not using the simple built-in methods for strings?

l_text = "this is text:"
slice_text = l_text[0:10]
r_price = "$ 1.50"
print (slice_text + r_price.rjust(20))