Font size
WorksheetsPython Programming Quiz
Total questions: 110
Worksheet time: 1hrs 7mins
Who developed Python Programming Language?
a) Wick van Rossum
b) Rasmus Lerdorf
c) Guido van Rossum
d) Niene Stom
Which of the following is the correct extension of the Python file?
a) .python
b) .pl
c) .py
d) .p
What will be the value of the following Python expression?
4 + 3 % 5
a) 7
b) 2
c) 4
d) 1
Which of the following is used to define a block of code in Python language?
a) Indentation
b) Key
c) Brackets
d) All of the mentioned
Which of the following character is used to give single-line comments in Python?
a) //
b) #
c) !
d) /*
What is the order of precedence in python?
a) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction
b) Exponential, Parentheses, Division, Multiplication, Addition, Subtraction
c) Parentheses, Exponential, Multiplication, Division, Subtraction, Addition
d) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
Which of the following functions is a built-in function in python?
a) factorial()
b) print()
c) seed()
d) sqrt()
Which of the following is not a core data type in Python programming?
a) Tuples
b) Lists
c) Class
d) Dictionary
To add a new element to a list we use which Python command?
a) list1.addEnd(5)
b) list1.addLast(5)
c) list1.append(5)
d) list1.add(5)
What will be the output of the following Python statement?
>>>"abcd"[2:]
a) a
b) ab
c) cd
d) dc
What will be the output of the following Python code?
>>> str1 = 'hello'
>>> str2 = ','
>>> str3 = 'world'
>>> str1[-1:]
a) olleh
b) hello
c) h
d) o
What will be the output of the following Python code?
>>>str1="helloworld"
>>>str1[::-1]
a) dlrowolleh
b) hello
c) world
d) helloworld
What will be the output of the “hello” +1+2+3?
a) hello123
b) hello
c) Error
d) hello6
Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?
a) 5
b) 4
c) None
d) Error
Suppose list1 is [2445,133,12454,123], what is max(list1)?
a) 2445
b) 133
c) 12454
d) 123
Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
a) [2, 33, 222, 14]
b) Error
c) 25
d) [25, 14, 222, 33, 2]
If a=(1,2,3,4), a[1:-1] is _________
a) Error, tuple slicing doesn’t exist
b) [2,3]
c) (2,3,4)
d) (2,3)
Which of the following statements create a dictionary?
a) d = {}
b) d = {“john”:40, “peter”:45}
c) d = {40:”john”, 45:”peter”}
d) All of the mentioned
What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
d["john"]
a) 40
b) 45
c) “john”
d) “peter”
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) {1: ‘A’, 2: ‘B’, 3: ‘C’}
b) Method update() doesn’t exist for dictionaries
c) {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}
d) {4: ‘D’, 5: ‘E’}
The code snippet above outputs
error
None
NaN
-1
What is the output of the code above
None
Syntax Error
-1
Code doesn't compile
The output of the code above is
Key Error
4
Math
The code above prints
Math
Physics
Chemistry
English
4
3.8
3.6
3.7
None
None
None
None
NaN
NaN
NaN
NaN
What is the output of the program above
e
y
t
g
The output of the code above is
[101, 102, 103, 104]
[3.6, 3.7, 3.8, 4]
What is the output of the code above
[3.6, 3.7, 3.8, 4]
[101, 102, 103, 104]
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.
grades[102]
grades.get(102)
grades[2]
grades[3]
grades.key(102)
Which of the following are valid ways to create a dictionary like this
Which of the following code deletes the key 103 and its value
del grades[103]
grades.pop(103)
del grades["103"]
grades.pop("103")
What is the output of the code above
3.9
4
Syntax error
What is the output of the program above
7
6
5
9
4
How to fix the syntax error above ?
grades.pop("Science", None)
grades.pop["Science","None"]
del grades["Math"]
del grades["Math", None]
What is the problem with the code above ?
Dictionary cannot be changed during an iteration
This code will run fine (without syntax errors)
After all the grades are popped, there are no elements remaining. The print statement will throw a syntax error.
The program above
prints all the odd numbers between 1 and 20
prints all even numbers between 1 and 20
print all the odd numbers between 1 and 21
prints all the even numbers between 1 and 21
The equivalent of the above for loop using the while syntax would be
The above program prints
Numbers 1 to 10 in reverse order
Numbers 1 to 11 in reverse order
Numbers 1 to 10
Numbers 1 to 11
The program above prints
Numbers between 1 and 100 that are multiples of 5
Numbers between 1 and 100
Numbers between 1 and 100 divisible by 5
Numbers between 1 and 101 that are multiples of 5
The code above prints all numbers between 1 and 30 that are
not divisible by 5
divisible by 5
The program above prints the sum of
all odd numbers less than 100
all even numbers less than 100
all numbers less than 100
The program above prints the sum of all the numbers between 0 and 101 that are
alternate odd numbers
alternate even numbers
alternate numbers
The program above prints each number between 1 and 10
as many times as the number itself
10 times
11 times
The program above prints each number between 1 and 10
as many times as the number itself
10 times
11 times
How many times will 1 be printed
3
4
5
6
for i in 100 :
print ( i )
Syntax error
prints numbers 0 to 100
prints numbers 1 to 100
prints numbers 0 to 99
prints numbers 1 to 99
What is the output of the program above
10
15
18
17
16
A while loop equivalent of the for loop above is
What is the value of the variable sum after the code above executes
54
44
64
34
74
What does this program print
2 + 2 = 4
4 + 4 = 8
8 + 8 = 16
16 + 16 = 32
32 + 32 = 64
2 + 2 = 4
2 + 2 = 4
2 + 2 = 4
2 + 2 = 4
2 + 2 = 4
2 + 2 = 4
2 + 4 = 6
2 + 6 = 8
2 + 8 = 10
2 + 10 = 12
2 + 2 = 4
2 + 2 = 4
2 + 2 = 4
2 + 2 = 4
2 + 2 = 4
2 + 4 = 6
2 + 6 = 8
2 + 8 = 10
Tuples in Python are mutable
False
True
How to create a single element tuple
(1,)
(1)
{1}
[1]
tuple([1])
Result of the program above is
('1', '2', '3', '4', '5')
(1, 2, 3, 4, 5)
12345
"12345"
What is the output of the program above
<class 'tuple'>
<class 'None'>
<class 'list'>
<class 'int'>
What is the output of the code above
(1, '2', 3, 4, 5)
syntax error
(1, 2, 3, 4, 5)
('1', '2', '3', '4', '5')
Which of the following is true
a is assigned a value of 1
b is assigned a value of [2,3]
b is assigned a value of (2,3)
b is assigned a value of 2
What is the output of the program above ?
b is bigger
a is bigger
Syntax error : tuples can't be compared
What is the output of the code above ?
1 4
1
1 None
1 [2,3,4]
1 (2,3,4)
What is the output of the program above ?
True
False
Select the statement to open a file named MYDATA.dat in read binary mode. Let the file object name be myfile.
myfile=open("MYDATA.dat","rb")
myfile=open("MYDATA.dat","r+")
myfile=open("MYDATA.dat","r")
Choose the correct statement to close a file stream named myfile:
myfile.terminate()
myfile.end()
myfile.close()
myfile.remove()
What will be the output-
f=open('abc.txt','a')
text="xyz"
f.write(text)
f.close()
Writing into the file without erasing old content
Writing into the file by erasing old content
reading from the file without erasing old content
reading from the file by erasing old content
The readlines() method returns
a. str
b. a list of lines
c. a list of single characters
d. a list of integers
What will be the output of the following Python code?
True
False
None
error
What refers to the behavior of the class
Attribute
Class
Object
Method
OOPs
Object Oriented Program
Object Oriented Programming
Object Opted Programming
Objective Oriented Programming
What create objects?
Classes
Functions
Methods
Modules
What are classes?
Blueprints/
Prototypes that defines methods and attributes
A thing which creates objects
A set of attributes and methods
A Blueprint of methods
What are Objects
Instances of a Class
Calling of a class
Identity of a class
Usables of a class
What are Attributes
Functions of a class
Variables of a class
Instance of a class
Variables of a code
What do Objects represent?
Uniqueness
Identity
Instance
Class
What refers to the State of a class?
Attributes
Methods
Constructors
Self
What refers to the behavior of the class
Attribute
Class
Object
Method
what is self?
Self represents the instance of the class in the class
Binds the Attr and methods
A default thing in classes with no use
None of the Above
How to call a method?
Obj.method
Obj.method()
Method(object)
Method.object
Making of a class
class NAME:
class NAME():
class (NAME):
class: Name()
The unexpected event happened during program execution should be handled by
EXCEPTION
EXPERIMENT
ASSERTION
EXTRAORDINARY
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
5.0
Something Went Wrong
Arithmetic Error
2.0
Exception disrupts the
Normal flow of the program
Abnornal flow of the program
Hard Disk
None of the Above
The suspicious code is put inside the
Try Block
Finally Block
Else Block
Except Block
________ statement can also be used without specifying Exception.
Try
Finally
Except
Else
try:
a=10/5
print (a)
except ArithmeticError:
print ("This statement is raising an exception" )
finally:
print (" final block executed " )
2.0
final block executed
This statement is raising an exception
final block executed
final block executed
2.0
An exception can be manually triggered by the command
raise
try
except
trigger
User defined Exceptions are created from the _________ Parent Class
Exception
Except
Handler
User Defined Exception
How many except statements can a try-except block have?
zero
one
more than one
more than zero
When will the else part of try-except-else be executed?
a) always
b) when an exception occurs
c) when no exception occurs
d) when an exception occurs in to except block
Is the following Python code valid?
try:
# Do something
except:
# Do something
else:
# Do something
no, there is no such thing as else
no, else cannot be used with except
no, else must come before except
yes
What will be the output of the following Python code?
lst = [1, 2, 3]
lst[3]
a) NameError
b) ValueError
c) IndexError
d) TypeError
What will be the output of the following Python code?
lst = [1, 2, 3]
lst[3]
a) NameError
b) ValueError
c) IndexError
d) TypeError
IndexError: list index out of range
13
10
12
9
Orange
Mango
Apple
Orange
Mango
Mango
Orange
Apple
Mango
Apple
Apple
Mango
ValueError: list.remove(x): x not in list
Apple
Mango
Orange
orange
Kiwi
Mango
Orange
Apple
Error
Error
[6.7, 7.7, 8.2, 8.1, 7.9, 5.8]
[5.8, 6.7, 7.7, 8.2, 8.1, 7.9]
[6.7, 7.7, 5.8, 8.2, 8.1, 7.9]
[6.7, 7.7, 8.2, 8.1, 7.9]
(6.7, 7.7, 8.2, 8.1, 7.9)
Error
6.7, 7.7, 8.2, 8.1, 7.9
[6.7, 7.7, 8.2, 8.1, 7.9]
"6.7, 7.7, 8.2, 8.1, 7.9"
Choose the appropriate code snippet which prints the following output.
My grade is 7
# For the given code snippet, choose the appropriate code snippet to print the mark of NSS.
print(marks['Non-academics']['NSS'])
print(marks['NSS'])
print(marks['NSS'])
print(marks['Non-academics'])
print(marks)
Error
Physics
80
Physics : 80
{'Physics': 80, 'Chemistry': 88, 'Mathematics': 92}
Error
( )
{'Physics': 80, 'Chemistry': 88, 'Mathematics': 92}
{'Chemistry': 88, 'Mathematics': 92}
{'Physics': 80, 'Chemistry': 88}
What is the maximum possible length of an identifier?
31 characters
63 characters
79 characters
Any length
Which of the following is not a keyword?
eval
assert
nonlocal
pass
Which of the following will run without errors?
round(7463.123,2,1)
round(6352.898,2,5)
round(45.8)
round()
What is the return type of function id?
dict
bool
float
int
To return the length of string s what command do we execute?
size(s)
s.size()
s.__len__()
len(s)
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)
0 1 2 0
error
0 1 2
none of the mentioned
What data type is the object below?
L = [1, 23, 'hello', 1]
list
dictionary
array
tuple
What is the output of this expression, 3*1**3?
27
9
1
3
What will be the output of the following Python code?
x = "abcdef"
while i in x:
print(i, end=" ")
a b c d e f
abcdef
i i i i i i …
error
Which of the following is the correct way to create a list in Python?
my_list = <1, 2, 3>
my_list = {1, 2, 3}
my_list = (1, 2, 3)
my_list = [1, 2, 3]
Which of the following is the correct way to define a function in Python?
function myFunction():
def myFunction():
define myFunction():
func myFunction():
What is the correct file extension for python files
.pyt
.pyth
.py
.pt
