Font size
WorksheetsPython Quiz-8 AX-1
Total questions: 126
Worksheet time: 1hrs 11mins
Which one of the following is external python module ?
random
os
numpy
datetime
__________ 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
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
What will be the output of the following code:
print type(type(int))
type 'int'
type 'type'
Error
0
What is the output of the following code :
L = ['a','b','c','d']
print "".join(L)
Error
None
abcd
[‘a’,’b’,’c’,’d’]
What is the output of the following segment:
chr(ord('A'))
A
B
a
Error
What is the output of the following program:
y = 8
z = lambda x : x * y
print z(6)
48
14
64
None of the above
What is called when a function is defined inside a class?
Module
Class
Another Function
Method
Which of the following is the use of id() function in python?
Id returns the identity of the object
Every object doesn’t have a unique id
All of the mentioned
None of the mentioned
What is the output of the following program:
import re
sentence = 'horses are fast'
regex = re.compile('(?P<animal>\w+) (?P<verb>\w+) (?P<adjective>\w+)')
matched = re.search(regex, sentence)
print(matched.groupdict())
{‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
(‘horses’, ‘are’, ‘fast’)
‘horses are fast’
‘are’
Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.pop(1)?
[3, 4, 5, 20, 5, 25, 1, 3]
[1, 3, 3, 4, 5, 5, 20, 25]
[3, 5, 20, 5, 25, 1, 3]
[1, 3, 4, 5, 20, 5, 25]
What is the meaning of using static before function declaration?
For example following function sum is made static
static int sum(int x, int y, int z)
{
return (x + y + z);
}
Static means nothing, sum() is same without static keyword.
Function need not to be declared before its use
Access to static functions is restricted to the file where they are declared
Static functions are made inline
How can we add two strings together?
s.join(s2)
s.add(s2)
s = s + s2
s ++ s2
2
11
2
21
2
3
11
2
3
21
Create a function named my_function for the following piece of code
--------------------------------------------- :
print("Hello from a function")
def my_function()
my_function()
def my_fun()
def my_function
Execute a function named my_function for the following piece of code
def my_function():
print("Hello from a function")
def my_function()
my_function()
my_function():
my_function();
Inside a function with two parameters, print the first parameter.
def my_function(fname, lname): print()
name
fname
lname
lname,fname
Let the function return the x parameter + 5. Complete the code
def my_function(x):
return (x + 5)
return (x)+ (5)
return x + 5
return x + 5;
If you do not know the number of arguments that will be passed into your function, there is a prefix you can add in the function definition, which prefix?
def my_function(___kids): print("The youngest child is " + kids[2])
*
**
#*
*#
Which of these defines a function that returns a value? (ignore white space)
def my_func():
x = 12
print('return',x)
def my_func():
return 12
def my_func():
x = 12
print(x)
def my_func(x):
print('return',x)
Which of the following defines a function with one parameter?
def my_func():
x = 12
return x
def my_func(x, y):
z = x + y
return z
def my_func(x):
z = x
return z
my_func(12)
print('result')
Which of the following returns the correct number of hours given the number of minutes?
def min_to_hr(minutes):
hours = minutes * 60
return hours
def min_to_hr(minutes):
hours = minutes / 60
return hours
def min_to_hr(minutes):
hours = minutes * 60
return minutes
def min_to_hr(minutes):
hours = minutes / 60
return minutes
This code would print 10 (T/F):
True
False
This code would print 5 (T/F):
True
False
What prints when this code runs?
3 4 40
1 2 14
3 4 14
1 2 40
What is the default return value for a function that does not return a value explicitly?
None
int
double
null
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 name given to that area of memory, where the system stores the parameters and local variables of a function call?
a heap
storage area
a stack
an array
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
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
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
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 the another term for calling a function?
(a)
The values received in the function definition header are called ,
(a)
The function calling another function is called the,
(a)
What is the name of the function in the picture given?
(a)
Which keyword marks the beginning of the function block?
(a)
What will be the output of the following code:
print (type(type(int)))
<class 'int'>
<class 'type'>
Error
0
1. Which of the following functions is a built-in function in python?
a) seed()
b) sqrt()
c) factorial()
d) print()
3. What will be the output of the following Python expression?
round(4.576)
a) 4.5
b) 5
c) 4
d) 4.6
5. What will be the output of the following Python function?
all([2,4,0,6])
a) Error
b) True
c) False
d) 0
6. What will be the output of the following Python expression?
round(4.5676,2)?
a) 4.5
b) 4.6
c) 4.57
d) 4.56
7. What will be the output of the following Python function?
any([2>8, 4>2, 1>2])
a) Error
b) True
c) False
d) 4 > 2
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
9. What is called when a function is defined inside a class?
a) class
b) function
c) method
d) module
12. What is a variable defined outside a function referred to as?
a) local variable
b) global variable
c) static variable
d) automatic variable
15. What error will occur when you execute the following code?
MANGO = APPLE
a) NameError
b) Syntax Error
c) Type Error
d) Value Error
What does this code do?
print("Hello world!")
Displays 'Hello world!' in the shell window.
Sends 'Hello world!' to the printer.
Waits for the user to type in 'Hello world!'
Displays 'hello, world.' in the shell window.
What does this function do?
input()
Opens the CD tray.
Asks the user to type something in.
Displays the word 'input'.
Exits the program.
What is a variable?
A number such as 25.
Plus, minus, multiply, divide or equals.
An array of text.
A storage location in the program which stores a value.
What is the process of converting one datatype to another called?
Data conversion.
Type Casting.
Type Conversion.
Concatenation.
Gjdk is not a good name for a variable, why?
It starts with a capital letter.
It does not contain any spaces.
There are no vowels.
It's meaningless.
What is an integer?
A number with a decimal point.
A whole number.
An array of characters.
A single character.
What function converts the data in a variable into a 'float'?
int()
flt()
bool()
float()
Comments are used to make code easier to read.
True
False
What would the program display if you ran this code and entered 2 and then 3 when prompted?
The total is 5.
The total is 23.
The total is 6.
An error.
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
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
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
Which of the following function convert a single character to its integer value in python?
unichr(x)
ord(x)
hex(x)
oct(x)
Which of the following function randomizes the items of a list in place?
shuffle(lst)
capitalize()
isalnum()
isdigit()
Hello
WorldWorldWorldWorldWorld
Hello
World5
Hello
World,World,World,World,World
Hello
HelloHelloHelloHelloHello
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
What is called when a function is defined inside a class?
Module
Class
Another function
Method
Python supports the creation of anonymous functions at runtime, using a construct called
lambda
Pi
anonymous
None
1
Nothing is displayed
0
An exception is thrown
Integer
Tuple
Dictionary
An exception is thrown
zzz
zz
An exception is executed
Infinite loop
0
1
Error
None
What will be the output of the following Python functions?
x=3
eval('x^2')
Error
1
9
6
Suppose there is a list such that: l=[2,3,4]. If we want to print this list in reverse order, which of the following methods should be used?
reverse(l)
list(reverse[(l)])
list(reversed(l))
reversed(l)
What will be the output of the following Python function?
hex(15)
f
0xF
0Xf
0xf
What is the correct way to sort the list 'B' using a method, the result should not return a new list, just change the list 'B'.
B. sort()
sorted(B)
sort(B)
B. sorted()
a is: 2 b is: 1 c is: 2
a is: 110 b is: 1 c is: 100
a is: 2 b is: 2 c is: 2
a is: 110 b is: 2 c is: 100
a is: 0 b is: 2 c is: 2
a is: 110 b is: 0 c is: 100
a is: 110 b is: 0 c is: 100
a is: 110 b is: 0 c is: 100
Error
33
3
None
If return statement is not used inside the function, the function will return:
None
0
Null
Arbitary value
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 stores the parameter and local variables of funtion call?
heap
stack
Uninitialized data segment
None
Which of the following function definition does not return any value?
a function that prints integers from 1 to 100.
a function that returns a random integer from 1 to 100.
a function that checks whether the current second is an integer from 1 to 100.
a function that converts an uppercase letter to lowercase.
