Unit 3 - Practice Quiz

INT108

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

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

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

A. def my_func[]:
B. function my_func():
C. def my_func():
D. create 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. 3.99
B. 4
C. 3
D. Error

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

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

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

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

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

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

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

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

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

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

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

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

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

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

12 What is a base case in recursion?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

23 What does math.sqrt(16) return?

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

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

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

25 What is the purpose of the return keyword?

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

26 What is explicit type conversion?

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

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

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

28 Which mathematical constant is available as math.pi?

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

29 What is the output of bool(0)?

A. True
B. False
C.
D. None

30 What is the output of bool(5)?

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

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

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

32 Can a Python function return multiple values?

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

33 What is a 'docstring' in a function?

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

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

A.
B. 1
C. undefined
D. Error

35 What is Indirect Recursion?

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

36 What will float(5) return?

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

37 Which of the following creates an anonymous function?

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

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

A.
B. None
C. Error
D. Undefined

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

A. 1
B. 1.0
C.
D. 3