String Formatting

  • + 0 comments
    def print_formatted(number):
        for i in range(1,number+1):
            w=len(bin(number)[2:])
            decimal=int(i)
            print(str(decimal).rjust(w),end=' ')
            octal=oct(i)[2:]
            print(octal.rjust(w),end=' ')
            hexa=hex(i)[2:].upper()
            print(hexa.rjust(w),end=' ')
            binary=bin(i)[2:]
            print(binary.rjust(w))