Programing/Python

[python] string formater

mjune.kim 2019. 4. 8. 15:46

https://pyformat.info/

 

PyFormat: Using % and .format() for great good!

Python has had awesome string formatters for many years but the documentation on them is far too theoretic and technical. With this site we try to show you the most common use-cases covered by the old and new style string formatting API with practical exam

pyformat.info

input

2

output

1  1  1   1

2 2 2 10


1
2
3
4
5
6
7
8
9
def print_formatted(number):
    # your code goes here
    width = len("{0:b}".format(number))
    for i in range(1, number+1):
        print("{0:{length}d} {0:{length}o} {0:{length}X} {0:{length}b}".format(i, length=width))
 
if __name__ == '__main__':
    n = int(input())
    print_formatted(n)
cs