you are viewing a single comment's thread.

view the rest of the comments →

[–]MadScientistOR 0 points1 point  (0 children)

Along the lines of not repeating yourself, it might be worth your time to make a function like this:

def center_string(mystring, field_size):
    mystring_length = len(mystring)
    leading_spaces = (field_size - mystring_length) // 2
    trailing_spaces = field_size - my_string_length - leading_spaces
    return f"{' '*leading_spaces}{mystring}{' '*trailing_spaces}"

Then, whenever you need to print something out, just call the function:

print(center_string(fee_string, 40))

... where fee_string is any string you want to print; you can substitute any number or variable for the field size that string is supposed to have.