String Formatting

  • + 0 comments

    Use the format function in python 3.

        w = len(format(number, 'b'))
        for i in range(1, number+1):
            dec = str(i).rjust(w)
            octal = format(i, 'o').rjust(w)
            hexa = format(i, 'X').rjust(w)
            binary = format(i, 'b').rjust(w)
            print(f"{dec} {octal} {hexa} {binary}")