def loops_stats(tree, num_lines):
    """
    Calculate the average number of loops.
    """
    total_loops = 0

    def traverse(node):
        nonlocal total_loops
        if node.type in ['for_statement', 'while_statement', 'do_statement']:
            total_loops += 1
        for child in node.children:
            traverse(child)

    traverse(tree.root_node)
    avg_loops = total_loops / num_lines
    return {'avg_loops': avg_loops}

    Calculate the average number of loops.
    
evaluation/benchmarks/testgeneval/compute_readability.py