String Formatting

Sort by

recency

|

1681 Discussions

|

  • + 0 comments

    def print_formatted(n): # your code goes here

    x = None
    lista = []
    max_longitud = len(bin(n).lstrip("0b"))
    # print(max_longitud)
    for i in range(1,n+1):
        hexadecimal = hex(i).lstrip("0x").rjust(max_longitud).upper()
        octadecimal = oct(i).lstrip("0o").rjust(max_longitud)
        binario = bin(i).lstrip("0b").rjust(max_longitud)
        # print(binario)
        longitud = len(binario)
        x = f"{str(i).rjust(max_longitud)} {octadecimal} {hexadecimal} {binario}"
        # x = str(i) + octadecimal + hexadecimal + binario
    
        print(x)
    

    if name == 'main': n = int(input()) print_formatted(n)

  • + 0 comments

    def print_formatted(number):

    # your code goes here
    
    w=len(f"{n:b}")
    
    for i in range (1, n+1): 
    
        print(f"{i:>{w}} {i:>{w}o} {i:>{w}X} {i:>{w}b}")
    
  • + 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)
    
  • + 1 comment
    def print_formatted(number):
        number_width = len(bin(number)[2:])
        values_type = ['d', 'o', 'X', 'b']
        for i in range(1,number+1):
            for v in values_type:
                print(f"{i: >{number_width}{v}}", end=' ')
            print()
    
    if __name__ == '__main__':
        n = int(input())
        print_formatted(n)
    
  • + 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))