wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Quiz-8 AX-1

Total questions: 126

Worksheet time: 1hrs 11mins

Name
Class
Date
1.

Which one of the following is external python module ?

a)

random

b)

os

c)

numpy

d)

datetime

2.

__________ keyword is used for creating a function in Python.

a)

define

b)

fun

c)

def

d)

function

3.

What is the output of the given code?

a)

10 20 10

b)

10

c)

20

d)

10 20

4.

What is the output of the given code?

a)

10 20 10 20

b)

10 20 10

c)

10 20 20

d)

Error

5.

Python supports variable number of parameters.

a)

True

b)

False

6.

Function header in Python contains _________________.

a)

function name

b)

list of parameters

c)

return type

d)

all the above

e)

Only A & B

7.

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

a)

null

b)

0

c)

None

d)

Garbage value

8.

__________ 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

9.

___________ 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

10.

times is ________________ type of argument.

a)

default arguments

b)

keyword arguments

c)

positional arguments

d)

arbitrary positional arguments

e)

arbitrary keyword arguments

11.

Select the advantages of functions

a)

Modular programming

b)

Code re-usability

c)

Improving clarity of the code

d)

All the above

12.

The output of the code above will be

a)

0

b)

1

c)

99

13.

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

14.

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

15.

Which of the following code is true

a)

square() will return 25

b)

square(3) will return 9

16.

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

17.

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

18.

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

19.

The output of the code above is

a)

<class 'tuple'>

b)

<class 'list'>

c)

<class 'dict'>

d)

<class 'string'>

e)

<class 'iterable'>

20.

The output of the code above is

a)

40

b)

30

c)

syntax error

21.

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

22.

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

23.

What are the two main types of functions?

a)

Custom function

b)

Built-in function & User defined function

c)

User function

d)

System function

24.

Where is function defined?

a)

Module

b)

Class

c)

Another function

d)

All of the mentioned

25.

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

a)

Module

b)

Class

c)

Another function

d)

Method

26.

Which of the following refers to mathematical function?

a)

sqrt

b)

rhombus

c)

add

d)

rhombus

27.

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

28.

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

29.

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

30.

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

31.

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

32.

What will be the output of the following code:


print type(type(int))

a)

type 'int'

b)

type 'type'

c)

Error

d)

0

33.

What is the output of the following code :


L = ['a','b','c','d']

print "".join(L)

a)

Error

b)

None

c)

abcd

d)

[‘a’,’b’,’c’,’d’]

34.

What is the output of the following segment:


chr(ord('A'))

a)

A

b)

B

c)

a

d)

Error

35.

What is the output of the following program:


y = 8

z = lambda x : x * y

print z(6)

a)

48

b)

14

c)

64

d)

None of the above

36.

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

a)

Module

b)

Class

c)

Another Function

d)

Method

37.

Which of the following is the use of id() function in python?

a)

Id returns the identity of the object

b)

Every object doesn’t have a unique id

c)

All of the mentioned

d)

None of the mentioned

38.

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

a)

{‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}

b)

(‘horses’, ‘are’, ‘fast’)

c)

‘horses are fast’

d)

‘are’

39.

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.pop(1)?

a)

[3, 4, 5, 20, 5, 25, 1, 3]

b)

[1, 3, 3, 4, 5, 5, 20, 25]

c)

[3, 5, 20, 5, 25, 1, 3]

d)

[1, 3, 4, 5, 20, 5, 25]

40.

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

}

a)

Static means nothing, sum() is same without static keyword.

b)

Function need not to be declared before its use

c)

Access to static functions is restricted to the file where they are declared

d)

Static functions are made inline

41.

How can we add two strings together?

a)

s.join(s2)

b)

s.add(s2)

c)

s = s + s2

d)

s ++ s2

42.
What will print ?
a)
cats eat mice
b)
mice get away
c)
unknown
d)
error message
43.
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
44.
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
45.
How do you correctly call this function
a)
def(1)
b)
x=square( )
c)
defSquare(4)
d)
x=square(5)
46.
What will print?
a)
1
2
11
b)
1
2
21
c)
1
2
3
11
d)
1
2
3
21
47.
What will print?
a)
nothing
b)
sayHi()
c)
an error message
d)
hi there
48.
What will print?
a)
5
b)
6
c)
3 2
d)
an error message
49.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
50.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
51.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
52.
What will print?
a)
nothing
b)
7
c)
z
d)
12
53.
How many times will Boo print?
a)
none
b)
4
c)
5
d)
1
54.
How many times will Boo print?
a)
none
b)
4
c)
5
d)
1
55.
How many times will Boo print?
a)
5
b)
4
c)
none
d)
infinite
56.
What will print?
a)
1 2
b)
1
c)
3
d)
5
57.
What will print?
a)
4
b)
5
c)
nothing
d)
an error message
58.
What will print?
a)
4
b)
5
c)
7
d)
an error message
59.

Create a function named my_function for the following piece of code

--------------------------------------------- :

print("Hello from a function")

a)

def my_function()

b)

my_function()

c)

def my_fun()

d)

def my_function

60.

Execute a function named my_function for the following piece of code

def my_function():

print("Hello from a function")

a)

def my_function()

b)

my_function()

c)

my_function():

d)

my_function();

61.

Inside a function with two parameters, print the first parameter.

def my_function(fname, lname): print()

a)

name

b)

fname

c)

lname

d)

lname,fname

62.

Let the function return the x parameter + 5. Complete the code

def my_function(x):

a)

return (x + 5)

b)

return (x)+ (5)

c)

return x + 5

d)

return x + 5;

63.

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

a)

*

b)

**

c)

#*

d)

*#

64.

Which of these defines a function that returns a value? (ignore white space)

a)

def my_func():

x = 12

print('return',x)

b)

def my_func():

return 12

c)

def my_func():

x = 12

print(x)

d)

def my_func(x):

print('return',x)

65.

Which of the following defines a function with one parameter?

a)

def my_func():

x = 12

return x

b)

def my_func(x, y):

z = x + y

return z

c)

def my_func(x):

z = x

return z

d)

my_func(12)

print('result')

66.

Which of the following returns the correct number of hours given the number of minutes?

a)

def min_to_hr(minutes):

hours = minutes * 60

return hours

b)

def min_to_hr(minutes):

hours = minutes / 60

return hours

c)

def min_to_hr(minutes):

hours = minutes * 60

return minutes

d)

def min_to_hr(minutes):

hours = minutes / 60

return minutes

67.

This code would print 10 (T/F):

a)

True

b)

False

68.

This code would print 5 (T/F):

a)

True

b)

False

69.

What prints when this code runs?

a)

3 4 40

b)

1 2 14

c)

3 4 14

d)

1 2 40

70.

What is the default return value for a function that does not return a value explicitly?

a)

None

b)

int

c)

double

d)

null

71.

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

a)

Function name only

b)

Both function name and parameter list

c)

parameter list only

d)

Return value

72.

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

a)

Func

b)

define

c)

def

d)

function

73.

What is the name given to that area of memory, where the system stores the parameters and local variables of a function call?

a)

a heap

b)

storage area

c)

a stack

d)

an array

74.

What Is The Output Of The Following Code Snippet?


def func(message, num = 1):

print(message * num)


func('Welcome')

func('Viewers', 3)

a)

Welcome

Viewers

b)

Welcome

ViewersViewersViewers

c)

Welcome

Viewers,Viewers,Viewers

d)

Welcome

75.

What Is The Output Of The Following Code Snippet?


def func(message, num = 1):

print(message * num)


func('Welcome')

func('Viewers', 3)

a)

Welcome

Viewers

b)

Welcome

ViewersViewersViewers

c)

Welcome

Viewers,Viewers,Viewers

d)

Welcome

76.

Which of the following function calls can be used to invoke the below function definition?


def test(a,b,c,d)

a)

test(1,2,3,4)

b)

test(a=1,2,3,4)

c)

test(a=1,b=2,c=3,4)

d)

test(a=1,b=2,c=3,d=4)

77.

what is a variable defined outside all the function referred to as?

a)

A static variable

b)

A global variable

c)

A local variable

d)

An automatic variable

78.

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

a)

return "number"

b)

print(number)

c)

print("number")

d)

return number

79.

What is the another term for calling a function?

(a)  

80.

The values received in the function definition header are called ,

(a)  

81.

The function calling another function is called the,

(a)  

82.

What is the name of the function in the picture given?

(a)  

83.

Which keyword marks the beginning of the function block?

(a)  

84.

What will be the output of the following code:


print (type(type(int)))

a)

<class 'int'>

b)

<class 'type'>

c)

Error

d)

0

85.

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

a)

a) seed()

b)

b) sqrt()

c)

c) factorial()

d)

d) print()

86.

3. What will be the output of the following Python expression?

round(4.576)

a)

a) 4.5

b)

b) 5

c)

c) 4

d)

d) 4.6

87.

5. What will be the output of the following Python function?


all([2,4,0,6])

a)

a) Error

b)

b) True

c)

c) False

d)

d) 0

88.

6. What will be the output of the following Python expression?


round(4.5676,2)?

a)

a) 4.5

b)

b) 4.6

c)

c) 4.57

d)

d) 4.56

89.

7. What will be the output of the following Python function?


any([2>8, 4>2, 1>2])

a)

a) Error

b)

b) True

c)

c) False

d)

d) 4 > 2

90.

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

a)

a) function name

b)

b) Parameter list

c)

c) return value

d)

d) Both A and B

91.

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

a)

a) class

b)

b) function

c)

c) method

d)

d) module

92.

12. What is a variable defined outside a function referred to as?

a)

a) local variable

b)

b) global variable

c)

c) static variable

d)

d) automatic variable

93.

15. What error will occur when you execute the following code?

MANGO = APPLE

a)

a) NameError

b)

b) Syntax Error

c)

c) Type Error

d)

d) Value Error

94.

What does this code do?

print("Hello world!")

a)

Displays 'Hello world!' in the shell window.

b)

Sends 'Hello world!' to the printer.

c)

Waits for the user to type in 'Hello world!'

d)

Displays 'hello, world.' in the shell window.

95.

What does this function do?

input()

a)

Opens the CD tray.

b)

Asks the user to type something in.

c)

Displays the word 'input'.

d)

Exits the program.

96.

What is a variable?

a)

A number such as 25.

b)

Plus, minus, multiply, divide or equals.

c)

An array of text.

d)

A storage location in the program which stores a value.

97.

What is the process of converting one datatype to another called?

a)

Data conversion.

b)

Type Casting.

c)

Type Conversion.

d)

Concatenation.

98.

Gjdk is not a good name for a variable, why?

a)

It starts with a capital letter.

b)

It does not contain any spaces.

c)

There are no vowels.

d)

It's meaningless.

99.

What is an integer?

a)

A number with a decimal point.

b)

A whole number.

c)

An array of characters.

d)

A single character.

100.

What function converts the data in a variable into a 'float'?

a)

int()

b)

flt()

c)

bool()

d)

float()

101.

Comments are used to make code easier to read.

a)

True

b)

False

102.

What would the program display if you ran this code and entered 2 and then 3 when prompted?

a)

The total is 5.

b)

The total is 23.

c)

The total is 6.

d)

An error.

103.

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

104.

What are the two main types of functions?

a)

Custom function

b)

Built-in function & User defined function

c)

User function

d)

System function

105.

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

106.

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

107.

Which of the following function convert a single character to its integer value in python?

a)

unichr(x)

b)

ord(x)

c)

hex(x)

d)

oct(x)

108.

Which of the following function randomizes the items of a list in place?

a)

shuffle(lst)

b)

capitalize()

c)

isalnum()

d)

isdigit()

109.
a)

Hello

WorldWorldWorldWorldWorld

b)

Hello

World5

c)

Hello

World,World,World,World,World

d)

Hello

HelloHelloHelloHelloHello

110.

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

111.

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

a)

Module

b)

Class

c)

Another function

d)

Method

112.

Python supports the creation of anonymous functions at runtime, using a construct called

a)

lambda

b)

Pi

c)

anonymous

d)

None

113.
a)

1

b)

Nothing is displayed

c)

0

d)

An exception is thrown

114.
a)

Integer

b)

Tuple

c)

Dictionary

d)

An exception is thrown

115.
a)

zzz

b)

zz

c)

An exception is executed

d)

Infinite loop

116.
a)

0

b)

1

c)

Error

d)

None

117.

What will be the output of the following Python functions?

x=3

eval('x^2')

a)

Error

b)

1

c)

9

d)

6

118.

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?

a)

reverse(l)

b)

list(reverse[(l)])

c)

list(reversed(l))

d)

reversed(l)

119.

What will be the output of the following Python function?

hex(15)

a)

f

b)

0xF

c)

0Xf

d)

0xf

120.

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

a)

B. sort()

b)

sorted(B)

c)

sort(B)

d)

B. sorted()

121.
a)

a is: 2 b is: 1 c is: 2

a is: 110 b is: 1 c is: 100

b)

a is: 2 b is: 2 c is: 2

a is: 110 b is: 2 c is: 100

c)

a is: 0 b is: 2 c is: 2

a is: 110 b is: 0 c is: 100

d)

a is: 110 b is: 0 c is: 100

a is: 110 b is: 0 c is: 100

122.
a)

Error

b)

33

c)

3

d)

None

123.

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

a)

None

b)

0

c)

Null

d)

Arbitary value

124.

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)

125.

In which part of memory does the system stores the parameter and local variables of funtion call?

a)

heap

b)

stack

c)

Uninitialized data segment

d)

None

126.

Which of the following function definition does not return any value?

a)

a function that prints integers from 1 to 100.

b)

a function that returns a random integer from 1 to 100.

c)

a function that checks whether the current second is an integer from 1 to 100.

d)

a function that converts an uppercase letter to lowercase.