Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Q1) Write a recursive function mylen(some_list) that determines the length of a list some list passed as an argument to this function. Call the function
Q1) Write a recursive function mylen(some_list) that determines the length of a list some list passed as an argument to this function. Call the function by writing the following piece of code: def main(): alist [43,76,97,86] print (mylen(alist)) main() The output of the above program segment would be: 4 NOTE: The function mylen should work with any list VERY IMPORTANT: your function cannot call the built-in Python function len()! Q2) Write a recursive function called isEven that returns True if number is even or returns False if number is odd Call the function by writing the following piece of code: def main(): nint(input("enter a number: ")) print("is", n, "even?", isEven (n)) main If the user enters 6 the output of the above program would be: Is 6 even? True If the user enters 13 the output of the above program would be: Is 13 even? False NOTE: You can assume that the user always enters a valid positive integer number. HINT : Subtracting 2 from an even number would eventually yield 0. Subtracting 2 from an odd number would eventually yield 1 Q3) Write a recursive function that computes and returns the sum of digits of an integer. Call the function by writing the following code: def main (): number-int(input( 'Enter a number:')) print (sumdigits (number)) main If the user enters the number 78411 the output of the above program would be: 21 NOTE: You can assume that the user always enters a valid positive integer number
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