Home > other >  How to place input function in center of page?
How to place input function in center of page?

Time:06-02

I want the user to be able to input their username beside the "username: " at the center but the results always be:

                                username:                                        example 

The "username: " is center which is what I want but the input text "example" is always not beside the "username:"

My code is below:

username = input("Username: ".center(165))

My desired outcome is:

                                               username: example

with it being in the center of the page.

CodePudding user response:

By doing input("Username: ".center(165)) you create a string of length 165 where "Username: " is placed right at the middle. So you get many spaces to the right of that string.

You want the "Username: " string to be at the right-end of the full string, so you should use rjust instead:

username = input("Username: ".rjust(165//2))
  • Related