Unit 3 - Practice Quiz

INT108 50 Questions
0 Correct 0 Wrong 50 Left
0/50

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

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

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 throws an error
B. It returns None
C. It returns False
D. It returns 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

12 What is a base case in recursion?

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

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

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

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

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

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

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

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

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

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. It is not possible
B. Declaring it in uppercase
C. Using the extern keyword
D. Using the global 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.sqr(x, y)
C. math.pow(x, y)
D. math.exp(x, y)

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

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

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

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

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

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

23 What does math.sqrt(16) return?

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

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

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

25 What is the purpose of the return keyword?

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

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. Compiler errors
B. Memory leaks
C. Syntax errors
D. Infinite recursion

28 Which mathematical constant is available as math.pi?

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

29 What is the output of bool(0)?

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

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. def calculate(5)
D. calculate[5]

32 Can a Python function return multiple values?

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

33 What is a 'docstring' in a function?

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

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

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

35 What is Indirect Recursion?

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

36 What will float(5) return?

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

37 Which of the following creates an anonymous function?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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. Error
D. 3

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

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

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

A. asc()
B. chr()
C. int()
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. Unlimited
B. 1000
C. 100
D. 10000

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

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