String Formatting

  • + 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)