Question: 3. Write a recursive function q3(item1, item2) that returns True or False depending on whether or not the two given input items are similar according
3. Write a recursive function q3(item1, item2) that returns True or False depending on whether or not the two given input items are "similar" according to the following definition. Two items are similar if:
- they are the same type or both are numbers (i.e. int or float type), and
- if they are lists, they are of the same length and each pair of corresponding list items (i.e. items with the same index) is similar.
For example,
>>> q3(True, False) items are same type and are not lists True >>> q3(1, 'a') items are different types False >>> q3[[],[]) True >>> q3([],[3]) list lengths differ False >>> q3(['c'],[3]) lists of same length but index 0 items are not similar False >>> q3([5.0],[3]) lists of same length and corresponding lists items are similar True >>> q3([1,2,['a','b']],[3,4, [1,2,3]]) items at index 2 are not similar False >>> q3([1,2,[False, 'b']],[3, 4, [True, 'hello']]) True >>> q3([[[[],[2],[],['hi', [0]]]]], [[[[],[-2],[],['bye', [1]]]]]) True >>> q3([[[[],[2],[],['hi', [0]]]]], [[[[],[-2],[],['bye', 0]]]])
3. Write a recursive function q3(iteml, item2) that returns True or False depending on whether or not the two given input items are "similar" according to the following definition. Two items are similar if: 1. they are the same type or both are numbers (i.e. int or float type), and 2. if they are lists, they are of the same length and each pair of corresponding list items (i.e. items with the same index) is similar. For example, >>> 93(True, False) items are same type and are not lists True >>> 93(1, 'a') items are different types False >>> 93[[],[]) True >>> 93([],[3]) list lengths differ False >>> 93(['c'],[3]) lists of same length but index 0 items are not similar False >>> 93([5.0],[3]) lists of same length and corresponding lists items are similar True >>> 43([1,2,['a','b']],[3,4, [1,2,3]]) items at index 2 are not similar False >>> 93([1,2, [False, 'b']],[3, 4, [True, 'hello']]) True >>> 93([[[[],[2],[],['hi', [0]]]]], [[[[],[-2],[],['bye', [1]]]]]) True >>> 93([[[[],[2],[],['hi', [0]]]]], [[[[],[-2],[],['bye', o]]]]) False
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts

