Unit 4: Functions and recursion - Subjective Questions

INT108 — Python Programming • Practice Questions with Detailed Answers

20 questions

1

Define a function call in Python. Explain how Python evaluates a function call with an example.

2

Distinguish between built-in functions, module functions, and user-defined functions in Python, with examples.

3

Explain type conversion and type coercion in Python. How are they different?

4

Describe the use of int(), float(), str(), and bool() for type conversion. Mention important limitations.

5

Explain how mathematical functions are used through Python's math module. Illustrate at least five important functions or constants.

6

Describe the steps involved in adding and using a new function in Python. Write a function that calculates the area of a rectangle.

7

Differentiate between parameters and arguments. Explain positional, keyword, and default arguments with examples.

8

Explain variable scope in relation to Python functions. Distinguish between local and global variables.

9

Distinguish between a fruitful function and a non-fruitful function. What value is returned when no explicit return is executed?

10

Explain function composition and nested function calls. Evaluate the expression math.sqrt(abs(-49)) step by step.

11

What is recursion? Explain the roles of the base case and the recursive case.

12

Derive a recursive algorithm for calculating the factorial of a non-negative integer and explain its execution.

13

Trace the execution of the recursive function below for mystery(4) and state its output.

PYTHON
def mystery(n):
    if n == 0:
        return 0
    return n + mystery(n - 1)
14

Write and explain a recursive function for finding the th Fibonacci number. Discuss the efficiency of the basic recursive solution.

15

Develop a recursive function to find the sum of the digits of a non-negative integer. Explain the base and recursive cases.

16

Derive a recursive implementation of Euclid's algorithm for finding the greatest common divisor of two integers.

17

Compare recursion and iteration. State their advantages, disadvantages, and suitable use cases.

18

What is infinite recursion? Explain how Python handles it and how recursive functions can be designed to avoid it.

19

Write a recursive function to determine whether a string is a palindrome. Explain how the string is reduced in each call.

20

Explain the use of return in recursive functions and describe how values travel through the call stack.