Unit 3: Functions and Recursion - Practice Quiz

INT108 — Python Programming 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 Which keyword is used to define a function in Python?

A. define
B. def
C. func
D. function

2 What is the correct syntax to define a function named 'my_func'?

A. function my_func():
B. create my_func():
C. def my_func():
D. def my_func[]:

3 What happens when a function is called without a return statement?

A. It returns 0
B. It returns None
C. It throws an error
D. It returns False

4 What is the output of: int(3.99)?

A. 4
B. 3
C. 3.99
D. Error

5 The process of automatically converting one data type to another is known as?

A. Type Coercion
B. Type Casting
C. Type Definition
D. Type Check

6 Which standard library module contains mathematical functions like sin, cos, and sqrt?

A. mathematics
B. sys
C. math
D. calc

7 What is the result of type(3 + 2.0)?

A. <class 'number'>
B. <class 'str'>
C. <class 'int'>
D. <class 'float'>

8 In a function definition def func(a, b):, what are a and b called?

A. Literals
B. Parameters
C. Arguments
D. Operators

9 When calling func(10, 20), what are 10 and 20 called?

A. Variables
B. Parameters
C. Arguments
D. Keywords

10 What does the math.ceil(4.2) function return?

A. 4.0
B. 4.2
C. 5
D. 4

11 What does the math.floor(4.9) function return?

A. 4
B. 5.0
C. 4.9
D. 5

12 What is a base case in recursion?

A. The most complex version of the problem
B. The first line of the function
C. The import statement
D. The condition that stops the recursion

13 What error occurs if a recursive function has no base case?

A. ValueError
B. TypeError
C. SyntaxError
D. RecursionError

14 Which of the following allows a function to accept an arbitrary number of positional arguments?

A. args[]
B. *params
C. *args
D. **kwargs

15 Which of the following allows a function to accept an arbitrary number of keyword arguments?

A. kwargs{}
B. **kwargs
C. *args
D. &kwargs

16 What is the output of str(10) + str(10)?

A. 1010
B. 10 + 10
C. 20
D. Error

17 What is the scope of a variable defined inside a function?

A. Local
B. Global
C. Universal
D. Static

18 How do you define a global variable inside a function?

A. Declaring it in uppercase
B. It is not possible
C. Using the global keyword
D. Using the extern keyword

19 Which function is used to calculate x to the power of y in the math module?

A. math.power(x, y)
B. math.exp(x, y)
C. math.sqr(x, y)
D. math.pow(x, y)

20 What is the output of abs(-7.5)?

A. -7.5
B. 7
C. 7.5
D. 8

21 Consider def f(x=10): return x. What is the result of f(5)?

A. Error
B. 5
C. 10
D. 15

22 Consider def f(x=10): return x. What is the result of f()?

A. 10
B. None
C. 5
D. Error

23 What does math.sqrt(16) return?

A. 4.0
B. 16
C. 256
D. 4

24 Which term describes passing arguments by name, like func(name='John')?

A. Positional arguments
B. Default arguments
C. Keyword arguments
D. Variable arguments

25 What is the purpose of the return keyword?

A. To define a parameter
B. To print a value to the console
C. To exit the function and pass back a value
D. To repeat the function

26 What is explicit type conversion?

A. Conversion done manually by the programmer using functions like int()
B. Defining a function
C. Automatic conversion by the interpreter
D. Converting string to list

27 Recursive functions must move towards the base case to avoid:

A. Compiler errors
B. Memory leaks
C. Syntax errors
D. Infinite recursion

28 Which mathematical constant is available as math.pi?

A. 1.618...
B. 2.71828...
C. 1.414...
D. 3.14159...

29 What is the output of bool(0)?

A. None
B. 0
C. True
D. False

30 What is the output of bool(5)?

A. False
B. True
C. None
D. 5

31 Which statement correctly calls a function named calculate with argument 5?

A. calculate[5]
B. call calculate(5)
C. def calculate(5)
D. calculate(5)

32 Can a Python function return multiple values?

A. Yes, as a tuple
B. No, only one value
C. No, it causes an error
D. Yes, as a string only

33 What is a 'docstring' in a function?

A. A string passed as an argument
B. A string variable defined inside the function
C. Documentation string appearing as the first statement in a function
D. An error message string

34 What is the factorial of 0 (math.factorial(0))?

A. Error
B. undefined
C. 0
D. 1

35 What is Indirect Recursion?

A. Recursion without a return statement
B. Function A calls Function A
C. Function A calls Function B, and Function B calls Function A
D. A function loop

36 What will float(5) return?

A. 5.0
B. Error
C. 5
D. Integer 5

37 Which of the following creates an anonymous function?

A. func
B. def
C. anon
D. lambda

38 In the expression x = y = z = 0, what is the value of x?

A. Undefined
B. None
C. Error
D. 0

39 What is the correct way to import only the sqrt function from the math module?

A. using math.sqrt
B. include math.sqrt
C. from math import sqrt
D. import math.sqrt

40 If a function definition uses *args, what is the data type of args inside the function?

A. Tuple
B. Dictionary
C. Set
D. List

41 If a function definition uses **kwargs, what is the data type of kwargs inside the function?

A. Tuple
B. Dictionary
C. Set
D. List

42 Which built-in function returns the length of a list or string?

A. count()
B. len()
C. length()
D. size()

43 What is the result of int('101', 2)?

A. Error
B. 5
C. 101
D. 2

44 What is the major disadvantage of using recursion over iteration?

A. Recursion is harder to write
B. Recursion cannot solve math problems
C. Recursion is always slower
D. Recursion uses more memory (stack space)

45 What is the output of: def func(a, b=5, c=10): return a + b + c followed by func(1, 2)?

A. 3
B. Error
C. 13
D. 8

46 Can positional arguments follow keyword arguments in a function call?

A. Only if they are integers
B. No
C. Yes
D. Only in recursive functions

47 Which function converts a character to its ASCII/Unicode integer value?

A. asc()
B. int()
C. chr()
D. ord()

48 Which function converts an integer ASCII/Unicode value to a character?

A. ord()
B. char()
C. chr()
D. str()

49 What is the default recursion limit in Python usually set to?

A. 10000
B. Unlimited
C. 1000
D. 100

50 What is the value of math.fmod(10, 3)?

A. 1.0
B. 1
C. 0
D. 3