String Formatting

  • + 0 comments
    def print_formatted(number):
        if not 0 <= number <= 99:
            return
        width = len(bin(number)[2:])
        for num in range(1, number + 1):
            print(f"{num:{width}d} {num:{width}o} {num:{width}X} {num:{width}b}")
    
    
    if __name__ == '__main__':
        n = int(input())
        print_formatted(n)