Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions

Question

1. What are the marketing implications of this situation?

Answered: 1 week ago

Question

Evaluate 3x - x for x = -2 Answer:

Answered: 1 week ago

Question

What is group replacement? Explain with an example. (2-3 lines)

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago