Font size
WorksheetsPython Quiz - 6 BF
Total questions: 88
Worksheet time: 3610secs
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
A named blocks of code that are designed to do one specific job is called as________
Loop
Function
Block
Branching
A Function which calls itself is called as (a)
While defining a function which of the
following symbol is used.
;(semi colon)
.(dot)
$(dollar)
:(colon)
Which function is called anonymous function?
Lambda
Recursion
Function
Define
Which keyword to be used to define a function in Python?
def
Local
Rec
Global
Which of the following is used, if you don’t need to type all the python code for the same task again and again?
Statement
Scope
Control Structure
Function
pow (5, 2) is equivalent to_______
5 * 2
5 * * 2
2 * * 5
2 * 5
How many types of functions are there in
python?
2
4
5
6
print (ord(‘A’) displays____
65
A
a
97
The default presidium of fixed point constant is______
7
6
8
16
Choose odd man out:
User Defined
Built-in
Parameters
Recursion
A_____ variable declared inside the function’s body is known as
File scope
Global scope
Local scope
Function scope
A block within a block is called ________block.
Nested
Control
Compressed
Called
The _____ function is inverse of ord () function.
Id()
Chr()
Bin()
None of these
Name the function that is used to create an empty list.
(a)
What will be the output of the following Code?
P = '~~Happy Diwali~~'
print(len(list(P))
(a)
Which function(s) out of the following will increase the length of the list?
insert()
index()
append()
extend()
reverse()
Select the output of the following code?
A = [10,5,'ABC', 3, 'XYZ', 4]
print(A.sort())
['ABC', 'XYZ', 3,4 5,10]
['XYZ', 'ABC', 10,5,4,3]
[ 3,4 5,10, 'ABC', 'XYZ',]
TypeError
Which function will add a list to the end of another list as a single element?
(a)
Select the functions from the following that carry out inplace operation in the given list.
sum()
clear()
insert()
sorted()
sort()
Which of the following is not a function in Python?
pop
remove
del
clear
Which function will return the position of the element in the list?
(a)
Write a single Python statement to add single element 'Honey' at the second location in the List L.
(a)
Write a single Python statement to remove the 8th element from the list named STUDENTS. You are not allowed to use a function in this statement.
(a)
Which out of these two functions accepts the position of the element to be deleted?
pop()
remove()
Select the output of the following statements?
a = [4,9.5,True, 'Delhi', 90.3, 10]
b = [4,9.5,True, 'Delhi', 90.3, 10]
c = ['Mohit', 'Male']
a.append(c)
b. extend(c)
print(len(a), len(b))
6 7
6 8
7 8
8 7
Write the parameter used in sort() function that is used for sorting the list in descending order.
(a)
Considering the given list, write a single Python statement to display the highest value from the list.
A = [100,4,2895,299,2828]
(a)
Write the output of the following statements?
A = [4,1,5,[10,20], 7, 8]
A.reverse()
print(A)
(a)
Select the output of the following coding statements?
A = ['Xyz', 'xyz', 'Abc', 'ABC']
A.sort()
print(A)
['Abc', 'ABC', 'Xyz', 'xyz']
['ABC', 'Abc', 'xyz', 'Xyz']
[ 'Xyz', 'xyz', 'ABC', 'Abc']
['ABC', 'Abc', 'Xyz', 'xyz']
Select the correct syntax of insert() function from the following.
<List name>.insert(<value>, <index position>)
<List name>.insert( <index position>, <value>)
Write a statement to delete value 'Amit' from a given list named as N.
(a)
Select the output of the following statements?
n = [1,2,3,[1,2],1,5]
print(n.count(1))
1
2
3
0
Write the output of the following statements?
a = [1,2,3,4]
b = a.pop()
print(a)
(a)
1)What is the output of the functions shown below?
float('1e-003')
float('2e+003')
a) 3.00 and 300
b) 0.001 and 2000.0
c) 0.001 and 200
d) Error and 2003
Which of the following is not a valid way to handle exceptions in Python?
A) try -except block
B) finally block
c) catch block
d) else block
3)Which header file uses-> gets()
Studio. h
Stdlib.h
Conio.h
All of the above
4)Which of the following is an important requirement of c programming?
Function
Input variables
Output variables
All of the above
5)In the following options which are python libraries which are used for data analysis and scientific computations
Numpy
Scipy
Pandas
All of the above
6)In the following options which are python libraries which are used for data analysis and scientific computations
Intrepreted language
portable
High level Language
More than one of the above
None of the above
)Which data structure is efficient to search the string in the dictionary that is containing a large number of strings?
A) Graph
B) Trie
C) Array
D) HashMap
8)Ramesh is working on array and he wants to pass the array to a function. If he is passing the array as an argument to a function, what actually he is passing?
A)The starting index of the array
B) The memory address of the first element of the array
C) The size of the array
D) A pointer to the first element of the array
9)Which bitwise operator is suitable for turning off a particular bit in a number?
&&
|
&
<<
10)Which of the following is not a valid way to handle exceptions in Python?
try -except block
finally block
catch block
else block
11)List is ……. Data structure
mutable
immutable
both mutable & immutable
None
12)give correct order naming for further symbols used in python
Symbols
/ // %
slash ,
double slash ,
percent
div,
floor divi,
modulus
floor divi,
div,
modulus
none
13)What is the output of the following a=[1,2,3,2,5]
b=2, c=[]
for i in a: c.append(i^b)A) [3,0,5,7,0]
B) [3,0,1,6,1]
C) [3,0,1,0,5]
D) [3,0,1,0,7]
14) What is the output of the following
def my_func(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return my_func(n-1) + my_func(n-2)
print(my_func(6))
A) 8
B) 12
C) 6
D) 15
15) What will be the result of the num1 variable after execution of the following statements?
int j = 1, num1 = 4;
while (++j <= 10)
{
num1++;
}
A) 13
B) 12
C)14
D)17
16) What is the output of the following
#include <stdio.h>
int main()
{
int i = 3;
printf("%d", (++i)++);
return 0;
}
A) 7
B) 9
C) 11
D) Error
17) What is the output of the following
def outer_function(x):
def inner_function(y):
return x * y
return inner_function
double = outer_function(2)
triple = outer_function(3)
print(double(4))
print(triple(4))
A) 8 , 12
B) 2, 3
C) 16 ,24
D) 4,6
18) What is the output of the following
#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5};
int *p = arr + 2;
printf("%d\n", p[1]);
return 0;
}
A) 1
B) 2
C) 3
D) 4
19)What will be the output of program?
main()
{
int n=(5,10,15);
cout<<n;
}
5
10
15
error
20) output ?
i=0
j=20
while i < j:
i = i+5
j = j - 5
print( i , j )
5 15
10 10
15 15
10 10
10 15
10 15
none
21) Output?
i=0
t=1
while i<=10:
if i%2==0:
t=t+1
i=i+1
print(t)
5
6
7
8
22) Output?
t=0
for i in range(10):
if i%2==0:
t=t+i
else:
t=t+1
print(t)
18
19
24
25
23) Output?
n=1996
if n%400==0:
print("Leap Year")
elif n%100==0:
print("Not Leap Year")
elif n%4==0:
print("Leap Year")
else:
print("Not Leap Year")
Not Leap Year
Leap Year
leap year
not leap year
24) What is the output of the following
If n is the size of input(positive), which function is most efficient(if the task to be performed is not an issue)?
A) for(i = 0; i < n; i++)
B) for(i = 0; i < n; i += 2)
C) for(i = 1; i < n; i *= 2)
D) for(i = n; i <= n; i /= 2)
E)None
