Question: Question 1: Sum of Leaves Consider a binary tree defined as in the book chapter, where a node can be either a number (an integer

Question 1: Sum of Leaves Consider a binary tree defined as in the book chapter, where a node can be either a number (an integer or floating-point number), or a tuple consisting of a left subtree, and a right subtree. Examples of trees are: 4.5 (3, 5) (3, (5, 7)) ((3, 4), ((4, 2), 9)) Write a function total(t) that takes the tree t, and returns the total of all the leaves in the tree. 1 def total(t): 2 ### YOUR CODE HERE [] 1 # This is a place where you can write additional tests to help you test 2 # your code, or debugging code, if you need. You can also leave it blank. 3 4 ### YOUR CODE HERE Here are some tests for your code. [] 1 # 5 points. Simple tests. 2 3 check_equal(total(5.4), 5.4) 4 check_equal(total((4, 6)), 10) 5 I] 1 * 5 points. Tests on trees. 2 3 check_equal(total(3, (4, (5, 6)))). 18) 4 check_equal(total(3, 4), 5), ((4, 3), (2, 1)))), 22) 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
