0

So I want to make something like that will print like this

100|
..50|
....0|

(the dots are there bc I couldnt make it appear in here without it) ive been thinking of using a for loop to check how many spaces it should have, but I'm just wondering if there is anything else that is more efficient

Jusepez
  • 3
  • 1
  • 1
    Does this answer your question? [Python - How can I pad a string with spaces from the right and left?](https://stackoverflow.com/questions/14776788/python-how-can-i-pad-a-string-with-spaces-from-the-right-and-left) – Code-Apprentice Aug 11 '22 at 04:38

1 Answers1

1

Try to use format() For example, the following script print from 0 to 100, align to right(>), and the space is 10 digits(10d)

for t in range(0,101,10):
    print("{:>10d}".format(t))
ALPHATU
  • 34
  • 4
  • Perfect, that work thank you very much! by the way, what does the ":>10d" mean? out of that the only think i understood was the use for the brackers but that was all – Jusepez Aug 11 '22 at 05:25
  • 1
    You can reference Format Specification Mini-Language as: [https://docs.python.org/3/library/string.html](https://docs.python.org/3/library/string.html) – ALPHATU Aug 11 '22 at 06:06
  • You can use an [f-string](https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals) to avoid the explicit call to `format()`: `print(f"{t:>10d}")` – GordonAitchJay Aug 11 '22 at 11:11