String Formatting

  • + 0 comments
    def print_formatted(number):
        # your code goes here
        width = len(bin(number).removeprefix('0b'))
        methods = ['','oct','hex','bin']
        prefixs = ['','0o','0x','0b']
    
        for i in range(1,number+1):
            for j,k in zip(methods,prefixs):
                if j != '':
                    y = eval(f"{j}({i}).removeprefix('{k}').upper()")
                else:
                    y = str(i)
                print(y.rjust(width),end= " ")
            print()