wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Quiz - 6 BF

Total questions: 88

Worksheet time: 3610secs

Name
Class
Date
1.

The output of the code above will be

a)

0

b)

1

c)

99

2.

How to add these two numbers

a)

age = int(age_1) + int(age_2)

b)

age = int(age_1 + age_2)

c)

age = age_1 + age_2

3.

The string enclosed in triple quotes is called the doc string. It is used to

a)

Show the documentation about the function

b)

be read by the developer reading the function code

4.

Which of the following code is true

a)

square() will return 25

b)

square(3) will return 9

5.

Which of the following is true

a)

The code above will result in syntax error

b)

square(2,2) will result in a value of 4

c)

square(2,3) will result in a value of 9

6.

The above code is the signature of the print function in Python.


*objects represents

a)

Variable number of arguments that can be passed as strings

b)

pointer to objects in memory

7.

The code above

a)

Takes in variable number of arguments and returns the sum of them

b)

Takes in a pointer to a list of numbers and returns the sum of them

8.

The output of the code above is

a)

<class 'tuple'>

b)

<class 'list'>

c)

<class 'dict'>

d)

<class 'string'>

e)

<class 'iterable'>

9.

The output of the code above is

a)

40

b)

30

c)

syntax error

10.

Which of the following is a feature of DocString?

a)

Provide a convenient way of associating documentation with Python modules, functions, classes, and methods

b)

All functions should have a docstring

c)

Docstrings can be accessed by the __doc__ attribute on objects

d)

All of the mentioned

11.

Which are the advantages of functions in python?

a)

Reducing duplication of code

b)

Decomposing complex problems into simpler pieces

c)

Improving clarity of the code

d)

All of the mentioned

12.

What are the two main types of functions?

a)

Custom function

b)

Built-in function & User defined function

c)

User function

d)

System function

13.

Where is function defined?

a)

Module

b)

Class

c)

Another function

d)

All of the mentioned

14.

What is called when a function is defined inside a class?

a)

Module

b)

Class

c)

Another function

d)

Method

15.

Which of the following refers to mathematical function?

a)

sqrt

b)

rhombus

c)

add

d)

rhombus

16.

What will be the output of the following Python code?

def cube(x):

return x * x * x


x = cube(3)

print (x)

a)

9

b)

3

c)

27

d)

30

17.

What will be the output of the following Python code?

y = 6

z=lambda x: x * y

print(z(8))

a)

12

b)

36

c)

16

d)

48

18.

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')

a)

Arthur Sir

b)

Sir Arthur

c)

Arthur

d)

None of the mentioned

19.

What is a variable defined inside a function referred to as?

a)

A global variable

b)

A volatile variable

c)

A local variable

d)

An automatic variable

20.

If a function doesn’t have a return statement, which of the following does the function return?

a)

int

b)

null

c)

None

d)

An exception is thrown without the return statement

21.

__________ keyword is used for creating a function in Python.

a)

define

b)

fun

c)

def

d)

function

22.

What is the output of the given code?

a)

10 20 10

b)

10

c)

20

d)

10 20

23.

What is the output of the given code?

a)

10 20 10 20

b)

10 20 10

c)

10 20 20

d)

Error

24.

Python supports variable number of parameters.

a)

True

b)

False

25.

Function header in Python contains _________________.

a)

function name

b)

list of parameters

c)

return type

d)

all the above

e)

Only A & B

26.

The default return value of any function in Python is _______________.

a)

null

b)

0

c)

None

d)

Garbage value

27.

__________ is the built-in function to know the type of a variable or function.

a)

id()

b)

type()

c)

data_type()

d)

none of the above

28.

___________ are the arguments passed to a function in correct positional order.

a)

Keyword arguments

b)

Default arguments

c)

Variable-length arguments

d)

Required arguments

e)

none of the above

29.

times is ________________ type of argument.

a)

default arguments

b)

keyword arguments

c)

positional arguments

d)

arbitrary positional arguments

e)

arbitrary keyword arguments

30.

Select the advantages of functions

a)

Modular programming

b)

Code re-usability

c)

Improving clarity of the code

d)

All the above

31.

A named blocks of code that are designed to do one specific job is called as________

a)

Loop

b)

Function

c)

Block

d)

Branching

32.

A Function which calls itself is called as (a)  

33.

While defining a function which of the

following symbol is used.

a)

;(semi colon)

b)

.(dot)

c)

$(dollar)

d)

:(colon)

34.

Which function is called anonymous function?

a)

Lambda

b)

Recursion

c)

Function

d)

Define

35.

Which keyword to be used to define a function in Python?

a)

def

b)

Local

c)

Rec

d)

Global

36.

Which of the following is used, if you don’t need to type all the python code for the same task again and again?

a)

Statement

b)

Scope

c)

Control Structure

d)

Function

37.

pow (5, 2) is equivalent to_______

a)

5 * 2

b)

5 * * 2

c)

2 * * 5

d)

2 * 5

38.

How many types of functions are there in

python?

a)

2

b)

4

c)

5

d)

6

39.

print (ord(‘A’) displays____

a)

65

b)

A

c)

a

d)

97

40.

The default presidium of fixed point constant is______

a)

7

b)

6

c)

8

d)

16

41.

Choose odd man out:

a)

User Defined

b)

Built-in

c)

Parameters

d)

Recursion

42.

A_____ variable declared inside the function’s body is known as

a)

File scope

b)

Global scope

c)

Local scope

d)

Function scope

43.

A block within a block is called ________block.

a)

Nested

b)

Control

c)

Compressed

d)

Called

44.

The _____ function is inverse of ord () function.

a)

Id()

b)

Chr()

c)

Bin()

d)

None of these

45.

Name the function that is used to create an empty list.

(a)  

46.

What will be the output of the following Code?

P = '~~Happy Diwali~~'

print(len(list(P))

(a)  

47.

Which function(s) out of the following will increase the length of the list?

a)

insert()

b)

index()

c)

append()

d)

extend()

e)

reverse()

48.

Select the output of the following code?

A = [10,5,'ABC', 3, 'XYZ', 4]

print(A.sort())

a)

['ABC', 'XYZ', 3,4 5,10]

b)

['XYZ', 'ABC', 10,5,4,3]

c)

[ 3,4 5,10, 'ABC', 'XYZ',]

d)

TypeError

49.

Which function will add a list to the end of another list as a single element?

(a)  

50.

Select the functions from the following that carry out inplace operation in the given list.

a)

sum()

b)

clear()

c)

insert()

d)

sorted()

e)

sort()

51.

Which of the following is not a function in Python?

a)

pop

b)

remove

c)

del

d)

clear

52.

Which function will return the position of the element in the list?

(a)  

53.

Write a single Python statement to add single element 'Honey' at the second location in the List L.

(a)  

54.

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)  

55.

Which out of these two functions accepts the position of the element to be deleted?

a)

pop()

b)

remove()

56.

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))

a)

6 7

b)

6 8

c)

7 8

d)

8 7

57.

Write the parameter used in sort() function that is used for sorting the list in descending order.

(a)  

58.

Considering the given list, write a single Python statement to display the highest value from the list.

A = [100,4,2895,299,2828]

(a)  

59.

Write the output of the following statements?

A = [4,1,5,[10,20], 7, 8]

A.reverse()

print(A)

(a)  

60.

Select the output of the following coding statements?

A = ['Xyz', 'xyz', 'Abc', 'ABC']

A.sort()

print(A)

a)

['Abc', 'ABC', 'Xyz', 'xyz']

b)

['ABC', 'Abc', 'xyz', 'Xyz']

c)

[ 'Xyz', 'xyz', 'ABC', 'Abc']

d)

['ABC', 'Abc', 'Xyz', 'xyz']

61.

Select the correct syntax of insert() function from the following.

a)

<List name>.insert(<value>, <index position>)

b)

<List name>.insert( <index position>, <value>)

62.

Write a statement to delete value 'Amit' from a given list named as N.

(a)  

63.

Select the output of the following statements?

n = [1,2,3,[1,2],1,5]

print(n.count(1))

a)

1

b)

2

c)

3

d)

0

64.

Write the output of the following statements?

a = [1,2,3,4]

b = a.pop()

print(a)

(a)  

65.

1)What is the output of the functions shown below?

float('1e-003')

float('2e+003')

a)

a) 3.00 and 300

b)

b) 0.001 and 2000.0

c)

c) 0.001 and 200

d)

d) Error and 2003

66.

Which of the following is not a valid way to handle exceptions in Python?

a)

A) try -except block

b)

B) finally block

c)

c) catch block

d)

d) else block

67.

3)Which header file uses-> gets()

a)

Studio. h

b)

Stdlib.h

c)

Conio.h

d)

All of the above

68.

4)Which of the following is an important requirement of c programming?

a)

Function

b)

Input variables

c)

Output variables

d)

All of the above

69.

5)In the following options which are python libraries which are used for data analysis and scientific computations

a)

Numpy

b)

Scipy

c)

Pandas

d)

All of the above

70.

6)In the following options which are python libraries which are used for data analysis and scientific computations

a)

Intrepreted language

b)

portable

c)

High level Language

d)

More than one of the above

e)

None of the above

71.

)Which data structure is efficient to search the string in the dictionary that is containing a large number of strings?

a)

A) Graph

b)

B) Trie

c)

C) Array

d)

D) HashMap

72.

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)

A)The starting index of the array

b)

B) The memory address of the first element of the array

c)

C) The size of the array

d)

D) A pointer to the first element of the array

73.

9)Which bitwise operator is suitable for turning off a particular bit in a number?

a)

&&

b)

|

c)

&

d)

<<

74.

10)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

75.

11)List is ……. Data structure

a)

mutable

b)

immutable

c)

both mutable & immutable

d)

None

76.

12)give correct order naming for further symbols used in python

Symbols

/ // %

a)

slash ,

double slash ,

percent

b)

div,

floor divi,

modulus

c)

floor divi,

div,

modulus

d)

none

77.
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)

A) [3,0,5,7,0]

b)

B) [3,0,1,6,1]

c)

C) [3,0,1,0,5]

d)

D) [3,0,1,0,7]

78.

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)

A) 8

b)

B) 12

c)

C) 6

d)

D) 15

79.

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)

A) 13

b)

B) 12

c)

C)14

d)

D)17

80.

16) What is the output of the following

#include <stdio.h>

int main()

{

int i = 3;

printf("%d", (++i)++);

return 0;

}

a)

A) 7

b)

B) 9

c)

C) 11

d)

D) Error

81.

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)

A) 8 , 12

b)

B) 2, 3

c)

C) 16 ,24

d)

D) 4,6

82.

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)

A) 1

b)

B) 2

c)

C) 3

d)

D) 4

83.

19)What will be the output of program?

main()

{

int n=(5,10,15);

cout<<n;

}

a)

5

b)

10

c)

15

d)

error

84.

20) output ?

i=0

j=20

while i < j:

i = i+5

j = j - 5

print( i , j )

a)

5 15

10 10

b)

15 15

10 10

c)

10 15

10 15

d)

none

85.

21) Output?

i=0

t=1

while i<=10:

if i%2==0:

t=t+1

i=i+1

print(t)

a)

5

b)

6

c)

7

d)

8

86.

22) Output?

t=0

for i in range(10):

if i%2==0:

t=t+i

else:

t=t+1

print(t)

a)

18

b)

19

c)

24

d)

25

87.

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")

a)

Not Leap Year

b)

Leap Year

c)

leap year

d)

not leap year

88.

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)

A) for(i = 0; i < n; i++)

b)

B) for(i = 0; i < n; i += 2)

c)

C) for(i = 1; i < n; i *= 2)

d)

D) for(i = n; i <= n; i /= 2)

e)

E)None