String Formatting

  • + 0 comments
    for i in range(1,n+1):
        ws=len(bin(number)[2:])
        decimal=str(i).rjust(ws)
        octal=oct(i)[2:].upper().rjust(ws)
        hexadecimal=hex(i)[2:].upper().rjust(ws)
        binary=bin(i)[2:].upper().rjust(ws)
        print(decimal,octal,hexadecimal,binary)