wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Test

Total questions: 80

Worksheet time: 40mins

Name
Class
Date
1.

In which of the following, data is stored permanently ?

a)

Variable

b)

File

c)

Both of the above

d)

None of the above

2.

NumPy stands for :

a)

Numbering Python

b)

Number In Python

c)

Numerical Python

d)

None of the above

3.

Which function returns the current position of file pointer?

a)

get()

b)

tell()

c)

seek()

d)

cur()

4.

What does readlines() method return?

a)

Dictionary

b)

String

c)

Tuple

d)

List

5.

Which of the following will read entire content of file (file object ‘f’) ?

a)

f.reads( )

b)

f.read( )

c)

f.read(all)

d)

f.read( * )

6.

In which software development phase quality of software is documented?

a)

Testing

b)

Delivery

c)

Idea

d)

Development

7.

Python is written in __________.

a)

Java

b)

C

c)

PHP

d)

All of the above

8.

Recursive function is __________.

a)

A function that calls itself

b)

A function that calls other functions

c)

Both (A) and (B)

d)

None of the above

9.

The connector symbol for flowchart is __________.

a)

Circle

b)

Parallelogram

c)

Diamond

d)

All the above

10.

To use a module in another module, you must import it using an ________ statement.

a)

import

b)

include

c)

both (A) and (B)

d)

none of the above

11.

f.read(5) will read __________ from a file (file object ‘f’).

a)

5 characters

b)

5 words

c)

5 lines

d)

None of the above

12.

The brain of a computer system is __________.

a)

RAM

b)

CPU

c)

ROM

d)

Control Unit

13.

Which of the following declarations is incorrect?

a)

1x = 2

b)

x = 3

c)

__xyz__ = 5

d)

None of these

14.

In python language, which of the following operators is the correct option for raising k to the power l ?

a)

k ^ l

b)

k**l

c)

k ^ ^ l

d)

k ^ *l

15.

Which symbol is used as a flowline to connect two blocks in a flow chart ?

a)

arrow

b)

circle

c)

box

d)

parallelogram

16.

A _______ statement is used when a statement is required syntactically but you do not want any code to execute.

a)

break

b)

pass

c)

continue

d)

none of these

17.

What will be the output of the following ? print(sum(1,2,3))

a)

Error

b)

6

c)

1

d)

3

18.

For performing the addition of two numbers, which of the following symbol in a flow chart are used ?

a)

Control flow

b)

Terminal

c)

Processing

d)

Decision

19.

Which of the following is not an advantage of using modules ?

a)

Provides a means of reuse of program code

b)

Provides a means of dividing up tasks

c)

Provides a means of reducing the size of the program

d)

Provides a means of testing individual parts of the program

20.

Which mode creates a new file if the file does not exist?

a)

write mode

b)

read mode

c)

append mode

d)

Both (A) and (C)

21.

Kite/diamond symbol in flow chart is used for __________.

a)

Execution

b)

Decision

c)

Statement

d)

All of the above

22.

What will be the output of the following Python code ? len([“hello”,2, 4, 6])

a)

Error

b)

6

c)

4

d)

3

23.

A _____________ stores information in the form of a stream of ASCII or unicode characters i.e. human readable.

a)

Text file

b)

Binary file

c)

Both (A) and (B)

d)

None of these

24.

Which function is used to add an element (5) in the list1 ?

a)

list1.sum(5)

b)

list1.append(5)

c)

list1.addelement(5)

25.

Which of the following functions is used to move the file pointer to a specific position in a file?

a)

getpos( )

b)

move( )

c)

position( )

d)

seek( )

26.

What is the use of the zeros() function in Numpy array in python ?

a)

To make a Matrix with all element 0

b)

To make a Matrix with all diagonal element 0

c)

To make a Matrix with first row 0

d)

None of the above

27.

Flow charts and Algorithms are used for __________.

a)

Better Programming

b)

Optimized Coding

c)

Systematic testing

d)

All the above

28.

What is the main purpose of using pseudocode in programming?

a)

Planning and organizing tasks

b)

Expressing algorithms in a language-independent manner

c)

Data analysis and visualization

d)

Debugging and testing software

29.

The contents inside the 'for loop' are separated by:

a)

colon

b)

comma

c)

semicolon

d)

hyphen

30.

What will be the output of the following Python code ?

tuple1=(5,1,7,6,2)

tuple1.pop(2)

print(tuple1)

a)

(5,1,6,2)

b)

(5,1,7,6)

c)

(5,1,7,6,2)

d)

Error

31.

What is the output of the following code snippet? print([i.lower() for i in 'HELLO'])

a)

hello

b)

['h', 'e', 'l', 'l', 'o']

c)

hel

d)

HELLO

32.

What will be the output of the following Python code? example = “helle” example.rfind(“e”)

a)

1

b)

2

c)

4

d)

5

33.

Choose the correct option with respect to Python.

a)

Both tuples and lists are immutable

b)

Tuples are immutable while lists are mutable

c)

Both tuples and lists are mutable

d)

Tuples are mutable while lists are immutable

34.

Which of the following is not a control structure ?

a)

Loop

b)

Process

c)

Decision

d)

None of these

35.

What type of data is : arr = [(1, 1), (2, 2), (3, 3)] ?

a)

List of tuples

b)

Tuples of lists

c)

Array of tuples

d)

Invalid type

36.

What will be the output of the following Python code ? example = “hello” example.rfind(“e”)

a)

1

b)

2

c)

4

d)

5

37.

The connector symbol for flowchart is ________.

a)

Circle

b)

Parallelogram

c)

Diamond

d)

All the above

38.

What is ‘f’ in the following statement ? f=open("Data.txt", "r")

a)

File Name

b)

File Handle

c)

Mode of file

d)

File Handling

39.

What is the output of following code? import numpy as np

a = np.array([[1,2,3],[4,5,6]])

print(a.shape)

a)

(2, 3)

b)

(3, 2)

c)

(1, 1)

d)

None of these

40.

What is the value of the following Python code ? >>>print(36 / 4)

a)

9

b)

4

c)

9.0

d)

4.0

41.

What will be the output of following ?

Y=[2,5J,6] Y.sort()

a)

[2,6,5J]

b)

[5J,2,6]

c)

Error

d)

[6,5J,2]

42.

Which of the following symbols is used to represent output in a flow chart?

a)

Square

b)

Circle

c)

Parallelogram

d)

Triangle

43.

What is the output of the following code ?

def s(n1):

print(n1)

n1 = n1 +2

n2=4

s(n2)

print(n2)

a)

6 4

b)

4 6

c)

4 4

d)

6 6

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.

What is the output of following code? >>>print(5*(2//3))

a)

3

b)

3.3

c)

0

d)

error

46.

In which format does a Binary file contain information?

a)

Quick response code

b)

Same format in which the data is held in memory

c)

ASCII format

d)

Unicode

47.

Which function is used to write data in binary mode?

a)

write

b)

writelines

c)

dump

d)

pickle

48.

The sequence logic will not be used while __________.

a)

Subtracting two numbers

b)

Comparing two data values

c)

Providing output to the user

d)

Adding two numbers

49.

Which of the following words is not a keyword of Python language?

a)

val

b)

raise

c)

try

d)

with

50.

Which of the following error is returned when we try to open a file in write mode which does not exist?

a)

File Found Error

b)

File Not Exist Error

c)

File Not Found Error

51.

What will be output for the following code? import numpy as np a = np.array([[1,2,3],[0,1,4]]) print (a.size)

a)

1

b)

5

c)

6

d)

4

52.

What will be the output of the following Python code ?

def display(b, n):

while n>0:

print(b, end=””)

n=n-1

display(‘z’, 3)

a)

zzz

b)

zz

c)

Infinite loop

d)

An exception is thrown

53.

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

a)

factorial()

b)

print()

c)

seed()

d)

sqrt()

54.

What 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 *

55.

What will be the output of following statement? >>>"m"+"nl"

a)

'm+nl'

b)

'mnl'

c)

'm nl'

d)

'm'

56.

What is the output of the following code ? import numpy as np

a = np.array([1,2,3,5,8])

b = np.array([0,3,4,2,1])

c = a + b

c = c*a

print (c[2])

a)

10

b)

21

c)

12

d)

28

57.

Which statement will return one line from a file (file object is ‘f’) ?

a)

f.readlines( )

b)

f.readline( )

c)

f.read( )

d)

f.line( )

58.

Which statement will move file pointer 10 bytes backward from current position ?

a)

f.seek(-10, 0)

b)

f.seek(10, 0)

c)

f.seek(-10, 1)

d)

none of the above

59.

What is the output of the following ? x=123 for i in x: print(i)

a)

1 2 3

b)

123

c)

Error

d)

None of these

60.

What is the output of the following code? import numpy as np a = np.array([1,2,3]) print(a.ndim)

a)

1

b)

2

c)

3

d)

0

61.

What is the output of the following ? print(max([1, 2, 3, 4], [4, 5, 6], [7]))

a)

[4, 5, 6]

b)

[7]

c)

[1, 2, 3, 4]

d)

7

62.

What will be the output of the following Python code? from math import * floor(11.7)

a)

12

b)

11

c)

11.0

d)

None of these

63.

What will be the output of the following expression? x = 14 print(x>>2)

a)

14

b)

1

c)

3

d)

2

64.

What will be the output of the following code snippet ?

numbers = (4, 7, 19, 2, 89, 45, 72, 22)

sorted_numbers = sorted(numbers)

odd_numbers = [x for x in sorted_numbers if x % 2 != 0]

print(odd_numbers)

a)

[7, 19, 45, 89]

b)

[2, 4, 22, 72]

c)

[4, 7, 19, 2, 89, 45, 72, 22]

d)

[2, 4, 7, 19, 22, 45, 72, 89]

65.

What will be the output of the following Python code?

>>>list1 = [1, 3]

>>>list2 = list1

>>>list1[0] = 4

>>>print(list2)

a)

[1, 4]

b)

[1, 3, 4]

c)

[4, 3]

d)

[1, 3]

66.

Which of the following is a valid arithmetic operator in Python ?

a)

//

b)

?

c)

<

d)

and

67.

In which format Binary file contains information?

a)

Quick response code

b)

Same format in which the data is held in memory

c)

ASCII format

d)

Unicode format

68.

What is the purpose of the 'break' statement in Python?

a)

To exit the current loop

b)

To skip the current iteration and move to the next one

c)

To define a new function

d)

None of the above

69.

What is the output of the following code snippet in Python?

x = 5 y = 2 print(x // y)

a)

2.5

b)

2

c)

3

d)

2.0

70.

Which of the following is true about Python dictionaries?

a)

They are ordered collections

b)

They can contain duplicate keys

c)

They are mutable

d)

None of the above

71.

What is the purpose of using comments in programming?

a)

To make the code more readable for humans

b)

To execute a specific block of code

c)

To declare variables

d)

To stop the execution of the program

72.

What does the 'len()' function do in Python?

a)

Returns the total number of elements in a list

b)

Converts a string to lowercase

c)

Performs a mathematical operation

d)

Checks for the presence of a substring in a string

73.

What is the purpose of using a 'while loop' in programming?

a)

To repeat a block of code until a condition is met

b)

To execute a block of code a specific number of times

c)

To define a function in Python

d)

To handle exceptions in the code

74.

Which of the following is not a valid data type in Python?

a)

Integer

b)

String

c)

Character

d)

Boolean

75.

What will be the output of the following code snippet?

for i in range(5):

print(i)

else:

print('Loop completed')

a)

0 1 2 3 4 Loop completed

b)

0 1 2 3 4

c)

Loop completed

d)

Error

76.

What is the output of the following Python code snippet?

print('hello'[::-1])

a)

olleh

b)

hello

c)

loleh

d)

None of the above

77.

What is the purpose of the 'pass' statement in Python?

a)

To skip the current iteration in a loop

b)

To indicate that no action is to be taken

c)

To raise an exception

d)

To exit the program

78.

Which method is used to remove the last element from a list in Python?

a)

list.remove()

b)

list.delete()

c)

list.pop()

d)

list.clear()

79.

What is the output of the following code snippet? example = 'hello' example.upper()

a)

'HELLO'

b)

'hello'

c)

'hELLO'

d)

'HELlo'

80.

What is the purpose of using pseudocode in programming?

a)

Planning and organizing tasks

b)

Expressing algorithms in a language-independent manner

c)

Data analysis and visualization

d)

Debugging and testing software