WorksheetsPython Functions and Methods
Total questions: 71
Worksheet time: 53mins
which keyword is used to import the modules in the python ?
import
importing
imported
none
if we only import the module then we need to use the function like -
function
module.function()
both
none
which statement is true about a module ?
module is the python program which describes functions, classes or variables.
module is a function in python
module can be anything in python
none
In how many ways we can import a module ?
1
2
3
none
python modules are saved with the extension -
.mod
.module
.py
none
What will be the output of the following code ?
25
0
5
none
which keyword is used to import the modules in the python ?
import
importing
imported
none
What is a library in python?
COLLECTION OF FILES
COLLECTION OF MODULES
IT IS SUBPROGRAM
NAME OF A FILE
Which of the statements is used to import all names from a module into the current calling module
import
from
dir()
import*
exp(),floor()belongs which module?
cmath.py
urlib.py
math.py
statistics.py
What will be the output of the following
from import factorial
print(math.factorial(5))
25
10
120
error bcz factorial is not a module in math
This program will produce
a random number between 10 and 100 (including 10 but not 100) always in increments of 10
a random number between 10 and 100 (including 10 and 100) always in increments of 10
10 random numbers between 10 and 100 (including 10 and 100)
10 random numbers between 10 and 100 (including 10 and not 100)
2. Which of the following functions is a built-in function in
python?
a) seed()
b) sqrt()
c) factorial()
d) print()
Suppose a function called add() is defined in a module called adder.py. Which of the following code snippets correctly show how to import and use the add() function? Select all that apply.
import adder
result = adder.add(2, 3)
from adder import add function
result = add(2, 3)
from adder file import add
result = adder.add(2, 3)
import add from adder
result = add(2, 3)
Which of the following is not an advantage of using modules?
Provides a means of testing individual parts of the program
Provides a means of reducing the size of the program
Provides a means of dividing up tasks
Provides a means of reuse of program code
What will be the output of the following Python function if the random module has already been imported?
random.randint(3.5,7)
Error
The integer closest to the mean of 3.5 and 7
Any integer between 3.5 and 7, excluding 7
Any integer between 3.5 and 7, including 7
Which keyword marks the beginning of the function block?
(a)
What is the another term for calling a function?
(a)
Write the name of the function which is not returning any value.
(a)
The values being passed through a function-call statement are called,
(a)
The values received in the function definition header are called ,
(a)
Python refers to the values being passed are called,
(a)
In function where the values being received are known as,
(a)
What is the name of the function in the picture given?
(a)
Which of the following items are present in the function header?
Function name only
Both function name and parameter list
parameter list only
Return value
Which of the following keywords marks the begining of the function block?
Func
define
def
function
What Is The Output Of The Following Code Snippet?
def func(message, num = 1):
print(message * num)
func('Welcome')
func('Viewers', 3)
Welcome
Viewers
Welcome
ViewersViewersViewers
Welcome
Viewers,Viewers,Viewers
Welcome
Fill in the line of code for calculating the factorial of a number.
def fact(num):
if num == 0:
return 1
else:
return _____________________
num*fact(num-1)
(num-1)*(num-2)
num*(num-1)
fact(num)*fact(num-1)
What is the output of the following piece of code?
def test(i,j):
if(i==0):
return j
else:
return test(i-1,i+j)
print(test(4,7))
13
7
Infinite Loop
17
Which of the following function calls can be used to invoke the below function definition?
def test(a,b,c,d)
test(1,2,3,4)
test(a=1,2,3,4)
test(a=1,b=2,c=3,4)
test(a=1,b=2,c=3,d=4)
what is a variable defined outside all the function referred to as?
A static variable
A global variable
A local variable
An automatic variable
what is a variable defined inside all the function referred to as?
A static variable
A global variable
A local variable
An automatic variable
Which of the given argument types can be skipped from a function call?
Positional arguments
keyword arguments
named arguments
default arguments
Pick one from the following statements to correctly complete the function body to get the output 5 in the given code snippet:
def f(number):
#missing function body
print(f(5))
return "number"
print(number)
print("number")
return number
What is a piece of code that can take inputs to perform a certain task?
a function
arguments
parameters
Consider the line of code:
Label('Go Team', 200, 100)
What is the Label?
argument
parameter
function name
Consider the line of code:
Label('Go Team', 200, 100)
What is 'Go Team' ?
argument
parameter
function name
When defining a function, the definition must occur before it is called.
true
false
Which of the following terms best describes the code above?
function call
function definition
What is the name for the code highlighted in red?
function name
function definition
parameters
arguments
Line 6 is called
function definition
function call
function name
The code highlighted in blue is best defined as:
function name
function call
function definition
arguments
parameters
What is a parameter in a function?
input value to a function for the function’s execution
a variable used to send information to a function
the name of the function
the name of the main program calling the function
The output of the code above will be
0
1
99
Which of the following code is true
square() will return 25
square(3) will return 9
square איך מזמנים את הפונקציה
def(1)
x=square( )
defSquare(4)
x=square(5)
How many values a function may return?
(a)
What types of values remain unaffected during function call statement?
Mutable objects
Immutable objects
Literal
Variables
A variable defined outside all functions have the lifetime of
(a)
Write the line of code that will call the function.
(a)
Write the line of code that will define the function, draw_coin
(a)
Do you call or define a function first?
call
define
Rewrite this line of code correctly!
(a)
Rewrite this line of code correctly!
(a)
Rewrite this line of code correctly!
(Hint: combine the words 'draw' and 'shape' into one word)
(a)
Rewrite the line of code that is written incorrectly to make it correct!
Hint: The mistake is when the function gets called
(a)
Write the line of code that will define the function, draw_hat
(a)
Which is the proper way to call a function?
8. Which of the following items are present in the function header?
a) function name
b) Parameter list
c) return value
d) Both A and B
10. If return statement is not used inside the function, the function will return:
a) None
b) 0
c) Null
d) Arbitary value
11. What will be the output of the following Python function?
import math
abs(math.sqrt(25))
a) Error
b) -5
c) 5
d) 5.0
13. Which of the following operators is the correct option for power(ab)?
a) a ^ b
b) a**b
c) a^^ b
d) a ^ * b
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 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
If we want to create a Python function that will roll dice for us, which of the below answers will run correctly?
def dice roll ():
def diceroll ()
def diceroll ():
def diceroll []:
