Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Solve it by PYTHON PLEASE. Functions Implement each function in a recursive manner (the tester will automatically check that you've done so). This means that
Solve it by PYTHON PLEASE.
Functions Implement each function in a recursive manner (the tester will automatically check that you've done so). This means that the function calls itself on a simpler set of inputs, and uses the result of that call to combine its own results. See our class materials for more information. recursive_len(xs): Given a list xs, write a function to calculate its length recursively. (Yes, this is a bit silly/wasteful, but it's a simple start for recursion). Each time the list isn't empty, its length can be found as one plus the length of all but the first item. .Assume: xs is a list. Restriction: do not call len() Examples recursive_len( [1,2,3] ) recursive len(] recursive-len( [0,0,0,0] ) lucas(n): The set of Lucas numbers begins with [2, 1, ] and then all successive elements are the sum of the previous two numbers. This function treats that sequence as a list, and is being asked to calculate and retrieve index n from it. Assume: n is a non-negative int. .Examples: lucas(e) lucas(1) lucas(2) lucas(5) lucas(10) 1 3 11 123 (" lucas(0)+lucas (1) 2+1) " remove_duplicates (msg): This function creates a new string that removes duplicates from consecutive spots (any time a character is repeated, the repeats are no longer present in the output). Assume: msg is a string. Examples: remove_duplicates("abbcccccaaabcc") "abcabc" "1e is a milion" remove-duplicates( "1000000 remove duplicates(") is a million") binary(n): Given an int n, convert it to binary. Hint: each time you divide a number by two, the remainder of 1 or is the rightmost bit in its binary representation; continually dividing by 2, the remainders will give you more and more bits in its binary representation from right to left, until the division itself (not the remainder) reaches zero and you're done. Example: n is eleven. 11%2=-L and 1 1//2--5. 5%2--L and 5//2--2. 2%2--o and 2//2-_ 1.1%2--L and 1//2-:0 (quotient is zero, so we're done). In reverse, that gave us 101 1. (101 1.--2**3 + 2** 1 + 2**0--8+3+11 1 10). Assume: n is a non-negative int. Restriction: do not call int) binary(5) binary(12) binary( 1038) Examples: "0" "101" "1100" "1000000110" binary(0) *Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started