1Which keyword is used to define a function in Python?
A.func
B.define
C.def
D.function
Correct Answer: def
Explanation:In Python, the 'def' keyword is used to start the definition of a function.
Incorrect! Try again.
2What 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():
Correct Answer: def my_func():
Explanation:The correct syntax uses 'def', followed by the function name, parentheses (), and a colon :.
Incorrect! Try again.
3What 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
Correct Answer: It returns None
Explanation:In Python, if a function does not explicitly return a value, it implicitly returns 'None'.
Incorrect! Try again.
4What is the output of: int(3.99)?
A.3.99
B.4
C.3
D.Error
Correct Answer: 3
Explanation:The int() function truncates the decimal part of a float, returning the integer part.
Incorrect! Try again.
5The process of automatically converting one data type to another is known as?
A.Type Casting
B.Type Coercion
C.Type Definition
D.Type Check
Correct Answer: Type Coercion
Explanation:Type Coercion is the automatic or implicit conversion of values from one data type to another (e.g., adding an int to a float results in a float).
Incorrect! Try again.
6Which standard library module contains mathematical functions like sin, cos, and sqrt?
A.calc
B.mathematics
C.math
D.sys
Correct Answer: math
Explanation:The 'math' module provides access to the mathematical functions defined by the C standard.
Incorrect! Try again.
7What is the result of type(3 + 2.0)?
A.<class 'int'>
B.<class 'float'>
C.<class 'str'>
D.<class 'number'>
Correct Answer: <class 'float'>
Explanation:When an integer is added to a float, Python coerces the integer to a float, resulting in a float.
Incorrect! Try again.
8In a function definition def func(a, b):, what are a and b called?
A.Arguments
B.Parameters
C.Literals
D.Operators
Correct Answer: Parameters
Explanation:Variables defined in the function declaration are called parameters.
Incorrect! Try again.
9When calling func(10, 20), what are 10 and 20 called?
A.Parameters
B.Arguments
C.Keywords
D.Variables
Correct Answer: Arguments
Explanation:The actual values passed to the function during a function call are called arguments.
Incorrect! Try again.
10What does the math.ceil(4.2) function return?
A.4
B.5
C.4.2
D.4.0
Correct Answer: 5
Explanation:math.ceil(x) returns the smallest integer greater than or equal to x.
Incorrect! Try again.
11What does the math.floor(4.9) function return?
A.4
B.5
C.4.9
D.5.0
Correct Answer: 4
Explanation:math.floor(x) returns the largest integer less than or equal to x.
Incorrect! Try again.
12What 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
Correct Answer: The condition that stops the recursion
Explanation:A base case is a condition in a recursive function that stops the recursion by returning a value without making a recursive call.
Incorrect! Try again.
13What error occurs if a recursive function has no base case?
A.SyntaxError
B.RecursionError
C.TypeError
D.ValueError
Correct Answer: RecursionError
Explanation:Infinite recursion leads to a stack overflow, which Python raises as a RecursionError: maximum recursion depth exceeded.
Incorrect! Try again.
14Which of the following allows a function to accept an arbitrary number of positional arguments?
A.*args
B.**kwargs
C.*params
D.args[]
Correct Answer: *args
Explanation:The single asterisk * before a parameter name (conventionally *args) collects extra positional arguments into a tuple.
Incorrect! Try again.
15Which of the following allows a function to accept an arbitrary number of keyword arguments?
A.*args
B.**kwargs
C.&kwargs
D.kwargs{}
Correct Answer: **kwargs
Explanation:The double asterisk ** before a parameter name (conventionally **kwargs) collects extra keyword arguments into a dictionary.
Incorrect! Try again.
16What is the output of str(10) + str(10)?
A.20
B.1010
C.Error
D.10 + 10
Correct Answer: 1010
Explanation:The str() function converts integers to strings. The + operator concatenates strings, resulting in '1010'.
Incorrect! Try again.
17What is the scope of a variable defined inside a function?
A.Global
B.Local
C.Universal
D.Static
Correct Answer: Local
Explanation:Variables defined inside a function are local to that function and cannot be accessed outside it.
Incorrect! Try again.
18How 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
Correct Answer: Using the global keyword
Explanation:The global keyword allows a user to modify a variable outside the current scope.
Incorrect! Try again.
19Which 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)
Correct Answer: math.pow(x, y)
Explanation:math.pow(x, y) returns x raised to the power of y as a float.
Incorrect! Try again.
20What is the output of abs(-7.5)?
A.-7.5
B.7.5
C.7
D.8
Correct Answer: 7.5
Explanation:The built-in abs() function returns the absolute (positive) value of a number.
Incorrect! Try again.
21Consider def f(x=10): return x. What is the result of f(5)?
A.10
B.5
C.15
D.Error
Correct Answer: 5
Explanation:The argument 5 overrides the default parameter value 10.
Incorrect! Try again.
22Consider def f(x=10): return x. What is the result of f()?
A.10
B.5
C.None
D.Error
Correct Answer: 10
Explanation:Since no argument is provided, the default parameter value 10 is used.
Incorrect! Try again.
23What does math.sqrt(16) return?
A.4
B.4.0
C.16
D.256
Correct Answer: 4.0
Explanation:math.sqrt() returns the square root as a float.
Incorrect! Try again.
24Which term describes passing arguments by name, like func(name='John')?
A.Positional arguments
B.Keyword arguments
C.Default arguments
D.Variable arguments
Correct Answer: Keyword arguments
Explanation:Keyword arguments allow you to pass arguments using the parameter name.
Incorrect! Try again.
25What 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
Correct Answer: To exit the function and pass back a value
Explanation:return exits the function execution and sends the specified value back to the caller.
Incorrect! Try again.
26What 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
Correct Answer: Conversion done manually by the programmer using functions like int()
Explanation:Explicit conversion (type casting) requires the programmer to specify the target type.
Incorrect! Try again.
27Recursive functions must move towards the base case to avoid:
A.Memory leaks
B.Syntax errors
C.Infinite recursion
D.Compiler errors
Correct Answer: Infinite recursion
Explanation:If the recursive step doesn't reduce the problem size toward the base case, the function calls itself indefinitely.
Incorrect! Try again.
28Which mathematical constant is available as math.pi?
A.3.14159...
B.2.71828...
C.1.414...
D.1.618...
Correct Answer: 3.14159...
Explanation:math.pi represents the mathematical constant π (pi).
Incorrect! Try again.
29What is the output of bool(0)?
A.True
B.False
C.
D.None
Correct Answer: False
Explanation:In Python, the integer 0 is considered falsy, so bool(0) returns False.
Incorrect! Try again.
30What is the output of bool(5)?
A.True
B.False
C.5
D.None
Correct Answer: True
Explanation:Non-zero numbers are considered truthy in Python.
Incorrect! Try again.
31Which statement correctly calls a function named calculate with argument 5?
A.call calculate(5)
B.calculate[5]
C.calculate(5)
D.def calculate(5)
Correct Answer: calculate(5)
Explanation:Functions are called by writing their name followed by parentheses containing the arguments.
Incorrect! Try again.
32Can 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
Correct Answer: Yes, as a tuple
Explanation:Python functions can return multiple values separated by commas, which are packed into a tuple.
Incorrect! Try again.
33What 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
Correct Answer: Documentation string appearing as the first statement in a function
Explanation:A docstring is a string literal used to document a function, usually enclosed in triple quotes.
Incorrect! Try again.
34What is the factorial of 0 (math.factorial(0))?
A.
B.1
C.undefined
D.Error
Correct Answer: 1
Explanation:Mathematically, 0! is defined as 1.
Incorrect! Try again.
35What 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
Correct Answer: Function A calls Function B, and Function B calls Function A
Explanation:Indirect recursion occurs when functions call each other in a cycle.
Incorrect! Try again.
36What will float(5) return?
A.5
B.5.0
C.Error
D.Integer 5
Correct Answer: 5.0
Explanation:The float() constructor converts the integer 5 to a floating-point number 5.0.
Incorrect! Try again.
37Which of the following creates an anonymous function?
A.def
B.func
C.lambda
D.anon
Correct Answer: lambda
Explanation:The lambda keyword is used to create small, anonymous functions.
Incorrect! Try again.
38In the expression x = y = z = 0, what is the value of x?
A.
B.None
C.Error
D.Undefined
Correct Answer:
Explanation:Python allows chained assignment; all variables are assigned the value 0.
Incorrect! Try again.
39What 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
Correct Answer: from math import sqrt
Explanation:The from ... import ... syntax allows importing specific attributes or functions from a module.
Incorrect! Try again.
40If a function definition uses *args, what is the data type of args inside the function?
A.List
B.Set
C.Tuple
D.Dictionary
Correct Answer: Tuple
Explanation:*args collects positional arguments into a tuple.
Incorrect! Try again.
41If a function definition uses **kwargs, what is the data type of kwargs inside the function?
A.List
B.Set
C.Tuple
D.Dictionary
Correct Answer: Dictionary
Explanation:**kwargs collects keyword arguments into a dictionary.
Incorrect! Try again.
42Which built-in function returns the length of a list or string?
A.size()
B.length()
C.len()
D.count()
Correct Answer: len()
Explanation:len() is the standard built-in function to get the length of a sequence.
Incorrect! Try again.
43What is the result of int('101', 2)?
A.101
B.5
C.2
D.Error
Correct Answer: 5
Explanation:int() can take a second argument specifying the base. Binary '101' equals decimal 5.
Incorrect! Try again.
44What 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
Correct Answer: Recursion uses more memory (stack space)
Explanation:Each recursive call adds a new frame to the call stack, which consumes memory and can lead to stack overflow.
Incorrect! Try again.
45What 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
Correct Answer: 13
Explanation:a gets 1, b gets 2 (overriding default), c uses default 10. 1 + 2 + 10 = 13.
Incorrect! Try again.
46Can positional arguments follow keyword arguments in a function call?
A.Yes
B.No
C.Only if they are integers
D.Only in recursive functions
Correct Answer: No
Explanation:In a function call, positional arguments must appear before keyword arguments.
Incorrect! Try again.
47Which function converts a character to its ASCII/Unicode integer value?
A.chr()
B.ord()
C.asc()
D.int()
Correct Answer: ord()
Explanation:ord() takes a single character string and returns its integer code point.
Incorrect! Try again.
48Which function converts an integer ASCII/Unicode value to a character?
A.chr()
B.ord()
C.str()
D.char()
Correct Answer: chr()
Explanation:chr() takes an integer and returns the corresponding string character.
Incorrect! Try again.
49What is the default recursion limit in Python usually set to?
A.100
B.1000
C.10000
D.Unlimited
Correct Answer: 1000
Explanation:The default recursion limit is typically 1000 to prevent infinite recursion from crashing the C stack.
Incorrect! Try again.
50What is the value of math.fmod(10, 3)?
A.1
B.1.0
C.
D.3
Correct Answer: 1.0
Explanation:math.fmod returns the floating-point remainder of division. 10 % 3 is 1.
Incorrect! Try again.
Give Feedback
Help us improve by sharing your thoughts or reporting issues.