wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 110

Worksheet time: 1hrs 7mins

Name
Class
Date
1.

Who developed Python Programming Language?

a)

a) Wick van Rossum

b)

b) Rasmus Lerdorf

c)

c) Guido van Rossum

d)

d) Niene Stom

2.

Which of the following is the correct extension of the Python file?

a)

a) .python

b)

b) .pl

c)

c) .py

d)

d) .p

3.

What will be the value of the following Python expression?

4 + 3 % 5

a)

a) 7

b)

b) 2

c)

c) 4

d)

d) 1

4.

Which of the following is used to define a block of code in Python language?

a)

a) Indentation

b)

b) Key

c)

c) Brackets

d)

d) All of the mentioned

5.

Which of the following character is used to give single-line comments in Python?

a)

a) //

b)

b) #

c)

c) !

d)

d) /*

6.

What is the order of precedence in python?

a)

a) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction

b)

b) Exponential, Parentheses, Division, Multiplication, Addition, Subtraction

c)

c) Parentheses, Exponential, Multiplication, Division, Subtraction, Addition

d)

d) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction

7.

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

a)

a) factorial()

b)

b) print()

c)

c) seed()

d)

d) sqrt()

8.

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

a)

a) Tuples

b)

b) Lists

c)

c) Class

d)

d) Dictionary

9.

To add a new element to a list we use which Python command?

a)

a) list1.addEnd(5)

b)

b) list1.addLast(5)

c)

c) list1.append(5)

d)

d) list1.add(5)

10.

What will be the output of the following Python statement?

>>>"abcd"[2:]

a)

a) a

b)

b) ab

c)

c) cd

d)

d) dc

11.

What will be the output of the following Python code?

>>> str1 = 'hello'

>>> str2 = ','

>>> str3 = 'world'

>>> str1[-1:]

a)

a) olleh

b)

b) hello

c)

c) h

d)

d) o

12.

What will be the output of the following Python code?

>>>str1="helloworld"

>>>str1[::-1]

a)

a) dlrowolleh

b)

b) hello

c)

c) world

d)

d) helloworld

13.

What will be the output of the “hello” +1+2+3?

a)

a) hello123

b)

b) hello

c)

c) Error

d)

d) hello6

14.

Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?

a)

a) 5

b)

b) 4

c)

c) None

d)

d) Error

15.

Suppose list1 is [2445,133,12454,123], what is max(list1)?

a)

a) 2445

b)

b) 133

c)

c) 12454

d)

d) 123

16.

Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?

a)

a) [2, 33, 222, 14]

b)

b) Error

c)

c) 25

d)

d) [25, 14, 222, 33, 2]

17.

If a=(1,2,3,4), a[1:-1] is _________

a)

a) Error, tuple slicing doesn’t exist

b)

b) [2,3]

c)

c) (2,3,4)

d)

d) (2,3)

18.

Which of the following statements create a dictionary?

a)

a) d = {}

b)

b) d = {“john”:40, “peter”:45}

c)

c) d = {40:”john”, 45:”peter”}

d)

d) All of the mentioned

19.

What will be the output of the following Python code snippet?

d = {"john":40, "peter":45}

d["john"]

a)

a) 40

b)

b) 45

c)

c) “john”

d)

d) “peter”

20.

What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}

b={4:"D",5:"E"}

a.update(b)

print(a)

a)

a) {1: ‘A’, 2: ‘B’, 3: ‘C’}

b)

b) Method update() doesn’t exist for dictionaries

c)

c) {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}

d)

d) {4: ‘D’, 5: ‘E’}

21.

The code snippet above outputs

a)

error

b)

None

c)

NaN

d)

-1

22.

What is the output of the code above

a)

None

b)

Syntax Error

c)

-1

d)

Code doesn't compile

23.

The output of the code above is

a)

Key Error

b)

4

c)

Math

24.

The code above prints

a)

Math

Physics

Chemistry

English

b)

4

3.8

3.6

3.7

c)

None

None

None

None

d)

NaN

NaN

NaN

NaN

25.

What is the output of the program above

a)

e

b)

y

c)

t

d)

g

26.

The output of the code above is

a)

[101, 102, 103, 104]

b)

[3.6, 3.7, 3.8, 4]

27.

What is the output of the code above

a)

[3.6, 3.7, 3.8, 4]

b)

[101, 102, 103, 104]

28.

Assume the key is the student's id and the value is the grade. Which of the following code will get the grade of student id 102.

a)

grades[102]

b)

grades.get(102)

c)

grades[2]

d)

grades[3]

e)

grades.key(102)

29.

Which of the following are valid ways to create a dictionary like this

a)
b)
c)
d)
e)
30.

Which of the following code deletes the key 103 and its value

a)

del grades[103]

b)

grades.pop(103)

c)

del grades["103"]

d)

grades.pop("103")

e)
31.

What is the output of the code above

a)

3.9

b)

4

c)

Syntax error

32.

What is the output of the program above

a)

7

b)

6

c)

5

d)

9

e)

4

33.

How to fix the syntax error above ?

a)

grades.pop("Science", None)

b)

grades.pop["Science","None"]

c)

del grades["Math"]

d)

del grades["Math", None]

34.

What is the problem with the code above ?

a)

Dictionary cannot be changed during an iteration

b)

This code will run fine (without syntax errors)

c)

After all the grades are popped, there are no elements remaining. The print statement will throw a syntax error.

35.

The program above

a)

prints all the odd numbers between 1 and 20

b)

prints all even numbers between 1 and 20

c)

print all the odd numbers between 1 and 21

d)

prints all the even numbers between 1 and 21

36.

The equivalent of the above for loop using the while syntax would be

a)
b)
c)
d)
37.

The above program prints

a)

Numbers 1 to 10 in reverse order

b)

Numbers 1 to 11 in reverse order

c)

Numbers 1 to 10

d)

Numbers 1 to 11

38.

The program above prints

a)

Numbers between 1 and 100 that are multiples of 5

b)

Numbers between 1 and 100

c)

Numbers between 1 and 100 divisible by 5

d)

Numbers between 1 and 101 that are multiples of 5

39.

The code above prints all numbers between 1 and 30 that are

a)

not divisible by 5

b)

divisible by 5

40.

The program above prints the sum of

a)

all odd numbers less than 100

b)

all even numbers less than 100

c)

all numbers less than 100

41.

The program above prints the sum of all the numbers between 0 and 101 that are

a)

alternate odd numbers

b)

alternate even numbers

c)

alternate numbers

42.

The program above prints each number between 1 and 10

a)

as many times as the number itself

b)

10 times

c)

11 times

43.

The program above prints each number between 1 and 10

a)

as many times as the number itself

b)

10 times

c)

11 times

44.

How many times will 1 be printed

a)

3

b)

4

c)

5

d)

6

45.

for i in 100 :

print ( i )

a)

Syntax error

b)

prints numbers 0 to 100

c)

prints numbers 1 to 100

d)

prints numbers 0 to 99

e)

prints numbers 1 to 99

46.

What is the output of the program above

a)

10

b)

15

c)

18

d)

17

e)

16

47.

A while loop equivalent of the for loop above is

a)
b)
c)
d)
48.

What is the value of the variable sum after the code above executes

a)

54

b)

44

c)

64

d)

34

e)

74

49.

What does this program print

a)

2 + 2 = 4

4 + 4 = 8

8 + 8 = 16

16 + 16 = 32

32 + 32 = 64

b)

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

c)

2 + 2 = 4

2 + 4 = 6

2 + 6 = 8

2 + 8 = 10

2 + 10 = 12

d)

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

e)

2 + 2 = 4

2 + 4 = 6

2 + 6 = 8

2 + 8 = 10

50.

Tuples in Python are mutable

a)

False

b)

True

51.

How to create a single element tuple

a)

(1,)

b)

(1)

c)

{1}

d)

[1]

e)

tuple([1])

52.

Result of the program above is

a)

('1', '2', '3', '4', '5')

b)

(1, 2, 3, 4, 5)

c)

12345

d)

"12345"

53.

What is the output of the program above

a)

<class 'tuple'>

b)

<class 'None'>

c)

<class 'list'>

d)

<class 'int'>

54.

What is the output of the code above

a)

(1, '2', 3, 4, 5)

b)

syntax error

c)

(1, 2, 3, 4, 5)

d)

('1', '2', '3', '4', '5')

55.

Which of the following is true

a)

a is assigned a value of 1

b)

b is assigned a value of [2,3]

c)

b is assigned a value of (2,3)

d)

b is assigned a value of 2

56.

What is the output of the program above ?

a)

b is bigger

b)

a is bigger

c)

Syntax error : tuples can't be compared

57.

What is the output of the code above ?

a)

1 4

b)

1

c)

1 None

d)

1 [2,3,4]

e)

1 (2,3,4)

58.

What is the output of the program above ?

a)

True

b)

False

59.

Select the statement to open a file named MYDATA.dat in read binary mode. Let the file object name be myfile.

a)

myfile=open("MYDATA.dat","rb")

b)

myfile=open("MYDATA.dat","r+")

c)

myfile=open("MYDATA.dat","r")

60.

Choose the correct statement to close a file stream named myfile:

a)

myfile.terminate()

b)

myfile.end()

c)

myfile.close()

d)

myfile.remove()

61.

What will be the output-

f=open('abc.txt','a')

text="xyz"

f.write(text)

f.close()

a)

Writing into the file without erasing old content

b)

Writing into the file by erasing old content

c)

reading from the file without erasing old content

d)

reading from the file by erasing old content

62.

The readlines() method returns

a)

a. str

b)

b. a list of lines

c)

c. a list of single characters

d)

d. a list of integers

63.

What will be the output of the following Python code?

a)

True

b)

False

c)

None

d)

error

64.

What refers to the behavior of the class

a)

Attribute

b)

Class

c)

Object

d)

Method

65.

OOPs

a)

Object Oriented Program

b)

Object Oriented Programming

c)

Object Opted Programming

d)

Objective Oriented Programming

66.

What create objects?

a)

Classes

b)

Functions

c)

Methods

d)

Modules

67.

What are classes?

a)

Blueprints/

Prototypes that defines methods and attributes

b)

A thing which creates objects

c)

A set of attributes and methods

d)

A Blueprint of methods

68.

What are Objects

a)

Instances of a Class

b)

Calling of a class

c)

Identity of a class

d)

Usables of a class

69.

What are Attributes

a)

Functions of a class

b)

Variables of a class

c)

Instance of a class

d)

Variables of a code

70.

What do Objects represent?

a)

Uniqueness

b)

Identity

c)

Instance

d)

Class

71.

What refers to the State of a class?

a)

Attributes

b)

Methods

c)

Constructors

d)

Self

72.

What refers to the behavior of the class

a)

Attribute

b)

Class

c)

Object

d)

Method

73.

what is self?

a)

Self represents the instance of the class in the class

b)

Binds the Attr and methods

c)

A default thing in classes with no use

d)

None of the Above

74.

How to call a method?

a)

Obj.method

b)

Obj.method()

c)

Method(object)

d)

Method.object

75.

Making of a class

a)

class NAME:

b)

class NAME():

c)

class (NAME):

d)

class: Name()

76.

The unexpected event happened during program execution should be handled by

a)

EXCEPTION

b)

EXPERIMENT

c)

ASSERTION

d)

EXTRAORDINARY

77.

try:

a=int(input("\n Enter a Value"))

b=int(input("\n Enter a Value "))

c=a/b

print (c)

except:

print("\n Something Went Wrong")


Assume a = 10 and b = 5, then the output will be

a)

5.0

b)

Something Went Wrong

c)

Arithmetic Error

d)

2.0

78.

Exception disrupts the

a)

Normal flow of the program

b)

Abnornal flow of the program

c)

Hard Disk

d)

None of the Above

79.

The suspicious code is put inside the

a)

Try Block

b)

Finally Block

c)

Else Block

d)

Except Block

80.

________ statement can also be used without specifying Exception.

a)

Try

b)

Finally

c)

Except

d)

Else

81.

try:

a=10/5

print (a)

except ArithmeticError:

print ("This statement is raising an exception" )

finally:

print (" final block executed " )

a)

2.0

final block executed

b)

This statement is raising an exception

final block executed

c)

final block executed

d)

2.0

82.

An exception can be manually triggered by the command

a)

raise

b)

try

c)

except

d)

trigger

83.

User defined Exceptions are created from the _________ Parent Class

a)

Exception

b)

Except

c)

Handler

d)

User Defined Exception

84.

How many except statements can a try-except block have?

a)

zero

b)

one

c)

more than one

d)

more than zero

85.

When will the else part of try-except-else be executed?

a)

a) always

b)

b) when an exception occurs

c)

c) when no exception occurs

d)

d) when an exception occurs in to except block

86.

Is the following Python code valid?


try:

# Do something

except:

# Do something

else:

# Do something

a)

no, there is no such thing as else

b)

no, else cannot be used with except

c)

no, else must come before except

d)

yes

87.

What will be the output of the following Python code?


lst = [1, 2, 3]

lst[3]

a)

a) NameError

b)

b) ValueError

c)

c) IndexError

d)

d) TypeError

88.

What will be the output of the following Python code?


lst = [1, 2, 3]

lst[3]

a)

a) NameError

b)

b) ValueError

c)

c) IndexError

d)

d) TypeError

89.
a)

IndexError: list index out of range

b)

13

c)

10

d)

12

e)

9

90.
a)

Orange

Mango

b)

Apple

Orange

Mango

c)

Mango

Orange

Apple

d)

Mango

Apple

e)

Apple

Mango

91.
a)

ValueError: list.remove(x): x not in list

b)

Apple

c)

Mango

d)

Orange

e)

orange

92.
a)

Kiwi

b)

Mango

c)

Orange

d)

Apple

e)

Error

93.
a)

Error

b)

[6.7, 7.7, 8.2, 8.1, 7.9, 5.8]

c)

[5.8, 6.7, 7.7, 8.2, 8.1, 7.9]

d)

[6.7, 7.7, 5.8, 8.2, 8.1, 7.9]

e)

[6.7, 7.7, 8.2, 8.1, 7.9]

94.
a)

(6.7, 7.7, 8.2, 8.1, 7.9)

b)

Error

c)

6.7, 7.7, 8.2, 8.1, 7.9

d)

[6.7, 7.7, 8.2, 8.1, 7.9]

e)

"6.7, 7.7, 8.2, 8.1, 7.9"

95.

Choose the appropriate code snippet which prints the following output.

My grade is 7

a)
b)
c)
d)
96.

# For the given code snippet, choose the appropriate code snippet to print the mark of NSS.

a)

print(marks['Non-academics']['NSS'])

b)

print(marks['NSS'])

c)

print(marks['NSS'])

d)

print(marks['Non-academics'])

e)

print(marks)

97.
a)

Error

b)

Physics

c)

80

d)

Physics : 80

e)

{'Physics': 80, 'Chemistry': 88, 'Mathematics': 92}

98.
a)

Error

b)

( )

c)

{'Physics': 80, 'Chemistry': 88, 'Mathematics': 92}

d)

{'Chemistry': 88, 'Mathematics': 92}

e)

{'Physics': 80, 'Chemistry': 88}

99.

What is the maximum possible length of an identifier?

a)

31 characters

b)

63 characters

c)

79 characters

d)

Any length

100.

Which of the following is not a keyword?

a)

eval

b)

assert

c)

nonlocal

d)

pass

101.

Which of the following will run without errors?

a)

round(7463.123,2,1)

b)

round(6352.898,2,5)

c)

round(45.8)

d)

round()

102.

What is the return type of function id?

a)

dict

b)

bool

c)

float

d)

int

103.

To return the length of string s what command do we execute?

a)

size(s)

b)

s.size()

c)

s.__len__()

d)

len(s)

104.

What will be the output of the following Python code?

i = 0

while i < 5:

print(i)

i += 1

if i == 3:

break

else:

print(0)

a)

0 1 2 0

b)

error

c)

0 1 2

d)

none of the mentioned

105.

What data type is the object below?

L = [1, 23, 'hello', 1]

a)

list

b)

dictionary

c)

array

d)

tuple

106.

What is the output of this expression, 3*1**3?

a)

27

b)

9

c)

1

d)

3

107.

What will be the output of the following Python code?

x = "abcdef"

while i in x:

print(i, end=" ")

a)

a b c d e f

b)

abcdef

c)

i i i i i i …

d)

error

108.

Which of the following is the correct way to create a list in Python?

a)

my_list = <1, 2, 3>

b)

my_list = {1, 2, 3}

c)

my_list = (1, 2, 3)

d)

my_list = [1, 2, 3]

109.

Which of the following is the correct way to define a function in Python?

a)

function myFunction():

b)

def myFunction():

c)

define myFunction():

d)

func myFunction():

110.

What is the correct file extension for python files

a)

.pyt

b)

.pyth

c)

.py

d)

.pt