wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Quiz BF-19-3-2024

Total questions: 123

Worksheet time: 2hrs 38mins

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.

Which keyword is used for function?*

a)

define

b)

fun

c)

def

d)

function

32.

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

33.

If the return statement is not used inside the function, the function will return:

a)

0

b)

None

c)

Null

d)

Arbitary value

34.

What is a recursive function?

a)

A function that calls other function.

b)

A function which calls itself.

c)

Both A and B

d)

None of the above

35.

Which of the following function headers is correct?*

a)

def fun(a = 2, b = 3, c)

b)

def fun(a = 2, b, c = 3)

c)

def fun(a, b = 2, c = 3)

d)

def fun(a, b, c = 3, d)

36.

In which part of memory does the system store the parameter and local variables of a function call?

a)

heap

b)

stack

c)

Uninitialized data segment

d)

None of the above

37.

How is a function declared in Python?*

a)

def function function_name():

b)

declare function function_name():

c)

def function_name():

d)

declare function_name():

38.

Which one of the following is the correct way of calling a function?

a)

function_name()

b)

call function_name()

c)

ret function_name()

d)

function function_name()

39.

Which of the following functions is a built-in function in python?

a)

array()

b)

sqrt()

c)

factorial()

d)

print()

40.

What will be the output of the following Python expression? round(4.576)

a)

4.5

b)

5

c)

4

d)

4.6

41.

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

42.

A Python module is a file with the _____ file extension that contains valid Python code.

a)

.pym

b)

.pymodule

c)

.module

d)

.py

43.

What is returned by math.ceil(3.4)?

a)

3

b)

4

c)

4.0

d)

3.0

44.

Which statement is correct to import all modules from the package

a)

from package import all

b)

from package import *

c)

from package include all

d)

from package include *

45.

(a)   is a string literal denoted by triple quotes for providing the specifications of certain program elements.

46.

Which of the following is not a valid namespace?

a)

Global namespace

b)

Public namespace

c)

Built-in namespace

d)

Local namespace

47.

What is the order of namespaces in which Python looks for an identifier?

a)

Python first searches the global namespace, then the local namespace and finally the built-in namespace

b)

Python first searches the local namespace, then the global namespace and finally the built-in namespace

c)

Python first searches the built-in namespace, then the global namespace and finally the local namespace

d)

Python first searches the built-in namespace, then the local namespace and finally the global namespace

48.

The collection of modules and packages that together cater to a specific type of applications or requirements, is called______

a)

module

b)

library

c)

classes

d)

documentation

49.

The help statement display ___ from a module.

a)

constants

b)

functions

c)

classes

d)

docstrings

50.
a)

10#40#70#

b)

30#40#50#

c)

50#60#70#

d)

40#50#70#

51.
a)

a=10

b)

a=20

c)

syntax error

d)

value error

52.
4 lines
53.
4 lines
54.
What will print ?
a)
cats eat mice
b)
mice get away
c)
unknown
d)
error message
55.
Which of the following best describes the order in which these lines are processed in Python?
a)
4, 1, 2
b)
4, 2, 1
c)
1, 2, 3, 4
d)
3, 1, 2
56.
Which of the following best describes the order in which these lines are processed in Python?
a)
1,2,3,4
b)
1,2,1,2,1,4
c)
1,2,1,2,1,2,4
d)
1,2,1,2,1,2,1,2,4
57.
How do you correctly call this function
a)
def(1)
b)
x=square( )
c)
defSquare(4)
d)
x=square(5)
58.
What will print?
a)
1
2
11
b)
1
2
21
c)
1
2
3
11
d)
1
2
3
21
59.
What will print?
a)
nothing
b)
sayHi()
c)
an error message
d)
hi there
60.
What will print?
a)
5
b)
6
c)
3 2
d)
an error message
61.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
62.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
63.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
64.
What will print?
a)
nothing
b)
7
c)
z
d)
12
65.
How many times will Boo print?
a)
none
b)
4
c)
5
d)
1
66.
How many times will Boo print?
a)
none
b)
4
c)
5
d)
1
67.
How many times will Boo print?
a)
5
b)
4
c)
none
d)
infinite
68.
What will print?
a)
1 2
b)
1
c)
3
d)
5
69.
What will print?
a)
4
b)
5
c)
nothing
d)
an error message
70.
What will print?
a)
4
b)
5
c)
7
d)
an error message
71.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
72.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
73.
What will print?
a)
1 2
b)
1
c)
3
d)
5
74.

Which of the following keywords marks the begining of the function block?

a)

Func

b)

define

c)

def

d)

function

75.

What is a piece of code that can take inputs to perform a certain task?

a)

a function

b)

arguments

c)

parameters

76.

Which of the following is the correct code to define a function?

a)

def area ( ):

b)

area ( )

c)

def area:

d)

def area ( )

77.

Which of the following is the correct way to call a function?

a)

def distance ( ):

b)

distance

c)

distance ( )

d)

distance ( ):

78.

In the provided code, which variables have not been defined?

a)

dist

b)

d

c)

rate

d)

time

79.

In the provided code, which values are parameters?

a)

rate

b)

5

c)

time

d)

8

e)

d

80.

In the provided code, which values are arguments?

a)

rate

b)

time

c)

5

d)

8

e)

d

81.

What are the valid data types for the parameters/arguments of the pre-built function, math.sprt ( ) ?

a)

integer

b)

float

c)

boolean

d)

string

82.

What is the correct data type for the value of cat?

cat = input("How many cats do you have?")

a)

string

b)

integer

c)

float

d)

boolean

83.

What is the final output for the provided function?

a)

No output, incorrect data types

b)

I have [num] cats named [name]

c)

"I have num cats named name"

d)

"I have 9 cats named Fred."

84.

What is the final output for the provided code?

a)

21

b)

108

c)

No Output

d)

x = 108

85.

What is the output for the provided code?

print(type(15 == 14))

a)

False

b)

Boolean

c)

Error: Data Type

d)

<class 'bool'>

86.

Python function always returns a value

a)

True

b)

False

87.

What is the output of the following code?

a)

15

b)

SyntaxError

c)

(5,10)

88.

Select which is true for Python function

a)

A Python function can return only a single value

b)

A function can take an unlimited number of arguments.

c)

A Python function can return multiple values

d)

Python function doesn’t return anything unless and until you add a return statement

89.

What is the output of the following function call

a)

5

b)

15

c)

(15,5)

d)

SyntaxError

90.

What will be the output?

a)

15

b)

8

c)

(8,7)

d)

SyntaxError

91.

What will be the output

a)

25

b)

NameError

c)

5

92.

Select which true for Python function

a)

A function is a code block that only executes when called and always returns a value.

b)

A function only executes when it is called and we can reuse it in a program

c)

Python doesn’t support nested function

93.

What is the output of the following function call

a)

Emma 25

b)

Emma 20

94.

What is the purpose of a function?

a)

They are reusable pieces of programs.

b)

They are required by the Python

c)

They allow us to compile our program

d)

They make the program larger

95.

What does the function header contain?

a)

The function name

b)

The function name and parameter list

c)

The parameter list

d)

The return value

96.

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

97.

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

98.

A variable that can be accessed from anywhere in a program is called?

a)

A global variable

b)

A volatile variable

c)

A local variable

d)

An automatic variable

99.

Python function always returns a value

a)

True

b)

False

100.

What is the output of the following code?

a)

15

b)

SyntaxError

c)

(5,10)

101.

Select which is true for Python function

a)

A Python function can return only a single value

b)

A function can take an unlimited number of arguments.

c)

A Python function can return multiple values

d)

Python function doesn’t return anything unless and until you add a return statement

102.

What is the output of the following function call

a)

5

b)

15

c)

(15,5)

d)

SyntaxError

103.

What will be the output?

a)

15

b)

8

c)

(8,7)

d)

SyntaxError

104.

What will be the output

a)

25

b)

NameError

c)

5

105.

Select which true for Python function

a)

A function is a code block that only executes when called and always returns a value.

b)

A function only executes when it is called and we can reuse it in a program

c)

Python doesn’t support nested function

106.

What is the output of the following function call

a)

Emma 25

b)

Emma 20

107.

What is the purpose of a function?

a)

They are reusable pieces of programs.

b)

They are required by the Python

c)

They allow us to compile our program

d)

They make the program larger

108.

What does the function header contain?

a)

The function name

b)

The function name and parameter list

c)

The parameter list

d)

The return value

109.

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

110.

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

111.

A variable that can be accessed from anywhere in a program is called?

a)

A global variable

b)

A volatile variable

c)

A local variable

d)

An automatic variable

112.

Which of the following items are present in the function header?

a)

function name

b)

function name and parameter list

c)

parameter list

d)

return value

113.

What is the output of the following code snippet:

a)

Welcome

Viewers

b)

Welcome

c)

Welcome

Viewers,Viewers,Viewers

d)

Welcome

ViewersViewersViewers

114.

What is the output of the following code snippet?

a)

1 3

b)

2 3

c)

The program has a runtime error because x and y are not defined.

d)

3 3

e)

3 2

115.

What is the output of the following code snippet?

a)

3 1

b)

3

1

c)

The program has a runtime error because x is not defined.

d)

3

3

e)

1 1

116.

What is the output of the following code snippet?

a)

4 1

b)

4

1

c)

The program has a runtime error because the local variable ‘num’ referenced before assignment.

d)

4

4

e)

4 4

117.
Which of the following function headers is correct?
a)
def f(a = 1, b = 1, c = 2, d):
b)
def f(a = 1, b = 1, c = 2):
c)
def f(a = 1, b, c = 2):
d)
def f(a = 1, b):
118.
What is a recursive function?
a)
A function that that calls all the functions in the program except itself.
b)
There is no such thing as recursive function in Python.
c)
A function that calls itself.
d)
A function that calls all the functions in the program.
119.

What is the output of following code snippet:

a)

10

b)

24

c)

7

d)

1

120.
If return statement is not used inside the function, the function will return:
a)
0
b)
Null
c)
None
d)
garbage value
e)
Error! Functions in Python must have a return statement.
121.

What is the output of following code snippet:

a)

15

b)

5 10

c)

(5,10)

d)

Syntax error

122.

What is the output of the following code snippet?

a)

1 3

b)

3 1

c)

The program has a runtime error because the function returns the multiple values

d)

3 -1

e)

-1 3

123.

What is the output of the following code snippet?

a)

x is 50

Changed global x to 2

Value of x is 50

b)

x is 50

Changed global x to 2

Value of x is 2

c)

x is 50

Changed global x to 50

Value of x is 50

d)

None of the mentioned