Python Only**
use fruitful branching recursion
Part B: tree {#partB .collapse}
In this part, you will write a four-parameter function called tree that draws branching trees and returns the total length of all branches and leaves in the tree. These tree examples demonstrate how it should work.
In the tree, everything starts with a trunk (which might end up being the branch of a larger tree), and the first parameter of the tree function specifies the length of the trunk. The next parameter specifies the number of layers of branches and leaves above the trunk, in each layer the tree splits into two parts, drawn 40° left and 40° right of the angle of the trunk. These parts have trunk lengths which are 60% of the original trunk length, and each has one less layer below it.
The last two parameters specify the trunk/branch color and the leaf color respectively: all branches are drawn using the first color and all leaves are drawn using the second color. Whenever the number of layers is 0, a leaf is drawn instead of a trunk. A leaf is a line of the given trunk length where the pen size is set to 1/2 of that length. For all other parts of the tree, the pen size is set to 1/10 of the trunk length.
Note that the trunk draws in whatever direction the turtle is facing when the function starts, and the function must return the turtle to this starting position when it is done.
A few important restrictions:
tree must be recursive, and it must not use any loops. For full credit, it should have exactly two recursive calls.
You must call pencolor to set the pen color and call pensize to set the pen size within tree (the pen size is 1/10th of the trunk length, except for leaves where it is 1/2 of the length).
For the test file to work correctly, you must draw each branch & leaf only once (as opposed to drawing it forward and backwards, even if this would look the same). You must also draw the leaves after the branches they're connected to, so that the leaves are drawn on top of the branches
Define tree with 4 parameters
Use def to define tree with 4 parameters
Do not use any kind of loop
Within the definition of tree with 4 parameters, do not use any kind of loop.
Call tree
Within the definition of tree with 4 parameters, call tree in at least one place.
Call pensize
Within the definition of tree with 4 parameters, call pensize in at least one place.
Call pencolor
Within the definition of tree with 4 parameters, call pencolor or color in at least one place.