0

I would like to add space after I write text and my variable in Python Format String. So I want to align and add 50 spaces such as the below picture.

Here is what I want to do: enter image description here

I wrote this code but it does not work

print("{:<50s}{}".format("Enter the point ID of unknown point ",i,)," :",end=" ")
1

2 Answers 2

1

You have to first format your prompt, and in a second step print this prompt:

prompt = f"Enter the point ID of unknown point {i}"
print(f"{prompt:<50s} : ", end="")

or count, how many places are left for the number:

print(f"Enter the point ID of unknown point {i:<14d} : ", end="")
Sign up to request clarification or add additional context in comments.

Comments

0

Use f-string literal to solve this

Spaces = ' ' * 50
print(f"Enter the point ID of unknown point : {i}{Spaces}")

Use {Spaces} wherever you want to add 50 spaces

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.