Font size
WorksheetsPython Quiz BF-19-3-2024
Total questions: 123
Worksheet time: 2hrs 38mins
The output of the code above will be
0
1
99
How to add these two numbers
age = int(age_1) + int(age_2)
age = int(age_1 + age_2)
age = age_1 + age_2
The string enclosed in triple quotes is called the doc string. It is used to
Show the documentation about the function
be read by the developer reading the function code
Which of the following code is true
square() will return 25
square(3) will return 9
Which of the following is true
The code above will result in syntax error
square(2,2) will result in a value of 4
square(2,3) will result in a value of 9
The above code is the signature of the print function in Python.
*objects represents
Variable number of arguments that can be passed as strings
pointer to objects in memory
The code above
Takes in variable number of arguments and returns the sum of them
Takes in a pointer to a list of numbers and returns the sum of them
The output of the code above is
<class 'tuple'>
<class 'list'>
<class 'dict'>
<class 'string'>
<class 'iterable'>
The output of the code above is
40
30
syntax error
Which of the following is a feature of DocString?
Provide a convenient way of associating documentation with Python modules, functions, classes, and methods
All functions should have a docstring
Docstrings can be accessed by the __doc__ attribute on objects
All of the mentioned
Which are the advantages of functions in python?
Reducing duplication of code
Decomposing complex problems into simpler pieces
Improving clarity of the code
All of the mentioned
What are the two main types of functions?
Custom function
Built-in function & User defined function
User function
System function
Where is function defined?
Module
Class
Another function
All of the mentioned
What is called when a function is defined inside a class?
Module
Class
Another function
Method
Which of the following refers to mathematical function?
sqrt
rhombus
add
rhombus
What will be the output of the following Python code?
def cube(x):
return x * x * x
x = cube(3)
print (x)
9
3
27
30
What will be the output of the following Python code?
y = 6
z=lambda x: x * y
print(z(8))
12
36
16
48
What will be the output of the following Python code?
def writer():
title = 'Sir'
name = (lambda x:title + ' ' + x)
return name
who = writer()
who('Arthur')
Arthur Sir
Sir Arthur
Arthur
None of the mentioned
What is a variable defined inside a function referred to as?
A global variable
A volatile variable
A local variable
An automatic variable
If a function doesn’t have a return statement, which of the following does the function return?
int
null
None
An exception is thrown without the return statement
__________ keyword is used for creating a function in Python.
define
fun
def
function
What is the output of the given code?
10 20 10
10
20
10 20
What is the output of the given code?
10 20 10 20
10 20 10
10 20 20
Error
Python supports variable number of parameters.
True
False
Function header in Python contains _________________.
function name
list of parameters
return type
all the above
Only A & B
The default return value of any function in Python is _______________.
null
0
None
Garbage value
__________ is the built-in function to know the type of a variable or function.
id()
type()
data_type()
none of the above
___________ are the arguments passed to a function in correct positional order.
Keyword arguments
Default arguments
Variable-length arguments
Required arguments
none of the above
times is ________________ type of argument.
default arguments
keyword arguments
positional arguments
arbitrary positional arguments
arbitrary keyword arguments
Select the advantages of functions
Modular programming
Code re-usability
Improving clarity of the code
All the above
Which keyword is used for function?*
define
fun
def
function
Which of the following items are present in the function header?
function name
parameter list
return value
Both A and B
If the return statement is not used inside the function, the function will return:
0
None
Null
Arbitary value
What is a recursive function?
A function that calls other function.
A function which calls itself.
Both A and B
None of the above
Which of the following function headers is correct?*
def fun(a = 2, b = 3, c)
def fun(a = 2, b, c = 3)
def fun(a, b = 2, c = 3)
def fun(a, b, c = 3, d)
In which part of memory does the system store the parameter and local variables of a function call?
heap
stack
Uninitialized data segment
None of the above
How is a function declared in Python?*
def function function_name():
declare function function_name():
def function_name():
declare function_name():
Which one of the following is the correct way of calling a function?
function_name()
call function_name()
ret function_name()
function function_name()
Which of the following functions is a built-in function in python?
array()
sqrt()
factorial()
print()
What will be the output of the following Python expression? round(4.576)
4.5
5
4
4.6
What will be the output of the following Python expression? round(4.5676,2)
4.5
4.6
4.57
4.56
A Python module is a file with the _____ file extension that contains valid Python code.
.pym
.pymodule
.module
.py
What is returned by math.ceil(3.4)?
3
4
4.0
3.0
Which statement is correct to import all modules from the package
from package import all
from package import *
from package include all
from package include *
(a) is a string literal denoted by triple quotes for providing the specifications of certain program elements.
Which of the following is not a valid namespace?
Global namespace
Public namespace
Built-in namespace
Local namespace
What is the order of namespaces in which Python looks for an identifier?
Python first searches the global namespace, then the local namespace and finally the built-in namespace
Python first searches the local namespace, then the global namespace and finally the built-in namespace
Python first searches the built-in namespace, then the global namespace and finally the local namespace
Python first searches the built-in namespace, then the local namespace and finally the global namespace
The collection of modules and packages that together cater to a specific type of applications or requirements, is called______
module
library
classes
documentation
The help statement display ___ from a module.
constants
functions
classes
docstrings
10#40#70#
30#40#50#
50#60#70#
40#50#70#
a=10
a=20
syntax error
value error
2
11
2
21
2
3
11
2
3
21
Which of the following keywords marks the begining of the function block?
Func
define
def
function
What is a piece of code that can take inputs to perform a certain task?
a function
arguments
parameters
Which of the following is the correct code to define a function?
def area ( ):
area ( )
def area:
def area ( )
Which of the following is the correct way to call a function?
def distance ( ):
distance
distance ( )
distance ( ):
In the provided code, which variables have not been defined?
dist
d
rate
time
In the provided code, which values are parameters?
rate
5
time
8
d
In the provided code, which values are arguments?
rate
time
5
8
d
What are the valid data types for the parameters/arguments of the pre-built function, math.sprt ( ) ?
integer
float
boolean
string
What is the correct data type for the value of cat?
cat = input("How many cats do you have?")
string
integer
float
boolean
What is the final output for the provided function?
No output, incorrect data types
I have [num] cats named [name]
"I have num cats named name"
"I have 9 cats named Fred."
What is the final output for the provided code?
21
108
No Output
x = 108
What is the output for the provided code?
print(type(15 == 14))
False
Boolean
Error: Data Type
<class 'bool'>
Python function always returns a value
True
False
What is the output of the following code?
15
SyntaxError
(5,10)
Select which is true for Python function
A Python function can return only a single value
A function can take an unlimited number of arguments.
A Python function can return multiple values
Python function doesn’t return anything unless and until you add a return statement
What is the output of the following function call
5
15
(15,5)
SyntaxError
What will be the output?
15
8
(8,7)
SyntaxError
What will be the output
25
NameError
5
Select which true for Python function
A function is a code block that only executes when called and always returns a value.
A function only executes when it is called and we can reuse it in a program
Python doesn’t support nested function
What is the output of the following function call
Emma 25
Emma 20
What is the purpose of a function?
They are reusable pieces of programs.
They are required by the Python
They allow us to compile our program
They make the program larger
What does the function header contain?
The function name
The function name and parameter list
The parameter list
The return value
Which are the advantages of functions in python?
Reducing duplication of code
Decomposing complex problems into simpler pieces
Improving clarity of the code
All of the mentioned
What is a variable defined inside a function referred to as?
A global variable
A volatile variable
A local variable
An automatic variable
A variable that can be accessed from anywhere in a program is called?
A global variable
A volatile variable
A local variable
An automatic variable
Python function always returns a value
True
False
What is the output of the following code?
15
SyntaxError
(5,10)
Select which is true for Python function
A Python function can return only a single value
A function can take an unlimited number of arguments.
A Python function can return multiple values
Python function doesn’t return anything unless and until you add a return statement
What is the output of the following function call
5
15
(15,5)
SyntaxError
What will be the output?
15
8
(8,7)
SyntaxError
What will be the output
25
NameError
5
Select which true for Python function
A function is a code block that only executes when called and always returns a value.
A function only executes when it is called and we can reuse it in a program
Python doesn’t support nested function
What is the output of the following function call
Emma 25
Emma 20
What is the purpose of a function?
They are reusable pieces of programs.
They are required by the Python
They allow us to compile our program
They make the program larger
What does the function header contain?
The function name
The function name and parameter list
The parameter list
The return value
Which are the advantages of functions in python?
Reducing duplication of code
Decomposing complex problems into simpler pieces
Improving clarity of the code
All of the mentioned
What is a variable defined inside a function referred to as?
A global variable
A volatile variable
A local variable
An automatic variable
A variable that can be accessed from anywhere in a program is called?
A global variable
A volatile variable
A local variable
An automatic variable
Which of the following items are present in the function header?
function name
function name and parameter list
parameter list
return value
What is the output of the following code snippet:
Welcome
Viewers
Welcome
Welcome
Viewers,Viewers,Viewers
Welcome
ViewersViewersViewers
What is the output of the following code snippet?
1 3
2 3
The program has a runtime error because x and y are not defined.
3 3
3 2
What is the output of the following code snippet?
3 1
3
1
The program has a runtime error because x is not defined.
3
3
1 1
What is the output of the following code snippet?
4 1
4
1
The program has a runtime error because the local variable ‘num’ referenced before assignment.
4
4
4 4
What is the output of following code snippet:
10
24
7
1
What is the output of following code snippet:
15
5 10
(5,10)
Syntax error
What is the output of the following code snippet?
1 3
3 1
The program has a runtime error because the function returns the multiple values
3 -1
-1 3
What is the output of the following code snippet?
x is 50
Changed global x to 2
Value of x is 50
x is 50
Changed global x to 2
Value of x is 2
x is 50
Changed global x to 50
Value of x is 50
None of the mentioned
