inserting into tree to insert into treewe use the same node class created above and add an insert class to it the insert class compares the value of the node to the parent node and decides to add it as left node or right node finallythe printtree class is used to print the tree class nodedef __init__(selfdata)self left none self right none self data data def insert(selfdata)compare the new value with the parent node if self dataif data self dataif self left is noneself left node(dataelseself left insert(dataelif data self dataif self right is noneself right node(dataelseself right insert(dataelseself data data print the tree def printtree(self)if self leftself left printtree(printself data)if self rightself right printtree(use the insert method to add nodes