Box & Name in python

Question:

Is there a way to get this to work? Have a full box and then have the name displayed in the center?

users_name = input (str(" Enter Your Name: "))
print("**************************************************")
print("*                                                *")
print("*                                                *")
print("*                                                *")
print("*                  users_name                    *")
print("*                                                *")
print("*                                                *")
print("*                                                *")
print("*                                                *")
print("*                                                *")
print("*                                                *")
print("**************************************************")
Asked By: MAMA

||

Answers:

You can use f-strings to replace the users_name in the text. Please see the link below for more details.

https://www.geeksforgeeks.org/formatted-string-literals-f-strings-python/

Answered By: ScottC

Use a formatting string to center the string in a specified width:

print(f"*{users_name:^48}*")

Python Docs:

Answered By: Mark Tolonen
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.