Home > Software engineering >  Box & Name in python
Box & Name in python

Time:10-04

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("**************************************************")

CodePudding user response:

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

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

Python Docs:

CodePudding user response:

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/

  • Related