Font size
S
M
L
XL
WorksheetsMid Term Practice AX
Total questions: 95
Worksheet time: 1hrs 11mins
Name
Class
Date
1.
What will be the value of the following Python expression?>>> 4 + 3 % 5
a)
7
b)
2
c)
4
d)
1
2.
What will be the output of the following Python function?
>>> min(max(0,-3,-4), 2, 7, False)
a)
0
b)
-3
c)
2
3.
Which are the wrong statements?
a)
s = "hello", [0]
s[-1][0] = 'p'
b)
s="hello"
S = 'self'[0] + 'hello' + s
c)
ls = []
out = ls if ls.pop() else 10
print(out)
d)
l=[1,3,4]
l.pop(2)
4.
What will be the output of the below Python code?
tupl=("annie","hena","sid")
print(tupl[-3:0])
a)
("annie")
b)
()
c)
None
d)
Error as slicing is not possible in tuple
5.
What will be the output of the below Python code?
tupl=()
tupl1=tupl*2
print(len(tupl1))
a)
0
b)
2
c)
1
d)
Error as tuple object has no attribute to len
6.
Output after execution of these lines?
>>> x = 3
>>> sum(x ** 3 for x in range(1) for x in range(1) if x % 3 == 1)
a)
Error
b)
27
c)
54
7.
Output of the following code?
a = True
b = False
c = True
if not a or b:
print ("a")
elif not a or not b and c:
print ("b")
elif not a or b or not b and a:
print ("c")
else:
print ("d")
a)
a
b)
b
c)
c
d)
d
8.
Study the following program:
a = [1]
while a:
a.append(a.count(1))
if a.count(1) > 1:
a.clear()
else:
a.append(100)
print(len(a))
Which of the following is correct output of this program?
a)
1
b)
3
c)
display nothing
9.
Which statements give the same output?
1. lst = [p for p in range(-1, 3)]
print(lst)
2. lst = [1]
for i in range(-1, -3):
lst.append(i)
print(lst)
3. lst = [(lambda x: -1)(i) for i in range(-1, -3) ]
print(lst)
4. print([])
a)
1 and 2
b)
3 and 4
c)
1 and 2 and 4
d)
None of the above
10.
Which of the following two Python codes will give same output?
(i) print(tupl[:-1])
(ii) print(tupl[0:5])
(iii) print(tupl[0:4])
(iv) print(tupl[-4:])
If tupl=(5,3,1,9,0)
a)
i, ii
b)
ii, iv
c)
i, iv
d)
i, iii
11.
Output after execution of these lines?
>>> t = (1, 2, 4, 3, 8, 9)
>>> [t[i] for i in range(0, len(t), 2)]
a)
[2, 3, 9]
b)
[1, 2, 4, 3, 8, 9]
c)
[1, 4, 8]
d)
(1, 4, 8)
12.
What is the output of the following program?
x = ['ab', 'cd']
for i in x:
i.upper()
print(x)
a)
['ab', 'cd']
b)
['AB', 'CD']
c)
['Ab', 'Cd']
13.
What will be the output of the following Python code?
a = 'hello'
hello = 'a'
lst = list(map(eval, [a]))
print(lst)
a)
[['a']]
b)
['a']
c)
[]
d)
None of the above
14.
Output after execution of these lines?
>>> s=["pune", "mumbai", "delhi"]
>>> [(w.upper(), len(w)) for w in s]
a)
Error
b)
[‘PUNE’, 4, ‘MUMBAI’, 6, ‘DELHI’, 5]
c)
[PUNE, 4, MUMBAI, 6, DELHI, 5]
d)
[(‘PUNE’, 4), (‘MUMBAI’, 6), (‘DELHI’, 5)]
15.
All keywords in Python are in _________
a)
A) Capitalized
b)
lower case
c)
UPPER CASE
d)
D) None of the mentioned
16.
Output after execution of these lines?
>>> a = '13405'
>>> a = sorted(a)[1:-1]
>>> print(*a)
a)
[1, 3, 4]
b)
'340'
c)
1 3 4
d)
None of the
17.
What happens when int('1.0') == 1 is executed?
a)
we get a True
b)
we get a False
c)
a TypeError occurs
d)
a ValueError occurs
18.
What can be the output of following Python code?
s = {0:0, 0:1, 9:1, 9.0:0}
print(s)
a)
{0: 1, 9: 0}
b)
{9:0, 0:0}
c)
. error
d)
{0:0, 9:1}
19.
Output after execution of these lines?
>>> d = {"john":40, "peter":45}
>>> "john" in d
a)
True
b)
False
c)
None
d)
Error
20.
What gets printed?
foo = eval('({ })')
print(type(foo))
a)
<class 'set'>
b)
<class 'dict'>
c)
<class 'tuple'>
d)
Error
21.
In file handling, what do these terms mean “r”, “a”?
a)
read, append
b)
append, read
c)
all of the mentioned
d)
none of the mentioned
22.
Which function is used to close a file in python?
a)
close()
b)
stop()
c)
end()
d)
closefile()
23.
math.floor() will do.....
a)
Rounds a number down to the nearest integer
b)
Rounds a number up to the nearest integer
c)
· no method exists in the math module of python.
d)
none of the above
24.
Which of the following is the use of the id() function in python?
a)
. Id() returns the size of the object.
b)
Id() returns the identity of the object.
c)
. Both A and B
d)
None of the above
25.
in each case is -6?
CODE 1
import math
num=int(input("Enter a number of whose factorial you want to find"))
print(math.factorial(num))
CODE 2
num=int(input("Enter a number of whose factorial you want to find"))
print(math.factorial(num))
a)
ValueError, NameError
b)
AttributeError, ValueError
c)
NameError, TypeError
d)
TypeError, ValueError
26.
Identify the type of error in the following Python lines?
Print(“Good Morning”)
print(“Good night)
a)
Syntax, Syntax
b)
NameError, Syntax
c)
NameError, Semantic
d)
Syntax, Semantic
27.
What is the result of sum([.1 for i in range(20)])?
a)
2
b)
20
c)
2
d)
2.0000000000000004'
28.
What will be the output of the following Python code snippet?
a = {1: "A", 2: "B", 3: "C"}
print(a.get(1,4))
a)
1
b)
A
c)
4
d)
Invalid syntax for get method
29.
What will be the output of the following Python code?
>>> a={1:"A",2:"B",3:"C"}
>>> a.items()
a)
Syntax error
b)
dict_items([(‘A’), (‘B’), (‘C’)])
c)
dict_items([(1,2,3)])
d)
dict_items([(1, ‘A’), (2, ‘B’), (3, ‘C’)])
30.
Which of the following functions accepts only integers as arguments?
a)
ord()
b)
min()
c)
chr()
d)
any()
31.
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)
reversed(l)
d)
list(reversed(l))
e)
None of the mentioned
32.
What will be the output of the following Python function?
float(' -12345\n')
(Note that the number of blank spaces before the number is 5)
a)
-12345.0 (5 blank spaces before the number)
b)
-12345.0
c)
Error
d)
-12345.000000000…. (infinite decimal places)
33.
What will be the output of the following Python function lines if execute individually?
ord(65)
ord(‘A’)
a)
A
65
b)
Error
65
c)
A
Error
d)
Error
Error
34.
What will be the output of the following Python function?
len(["hello",2, 4, 6][:])
a)
4
b)
3
c)
Error
d)
6
35.
What is the output of the following code?
print(9//2)
a)
4.5
b)
4.0'
c)
4
d)
1
36.
What is the output of the following?
i = 0
while i < 3:
print(i, end = ' ')
i++
print(i+1, end = ' ')
a)
012'
b)
01122'
c)
0123'
d)
Error
37.
What is the output of the expression : 3*1**3
a)
27
b)
9
c)
3
d)
1
38.
Question
What is the output of the following program :
i = 0
while i < 3:
print(i, end = ' ')
i += 1
else:
print(0)
a)
0 1 2 3 0'
b)
0 1 2 0'
c)
0 1 2'
d)
Error
39.
Study the following code snippet?
print(print(print("hello")))
What will be the output?
a)
hello None None
b)
None None hello
c)
None hello None
d)
hello
40.
What will be the output of the following Python code?
x=13
if x>12 or x<15 and x==16:
print("Given condition matched")
else:
print("Given condition did not match")
a)
Given condition matched
b)
Given condition did not match
c)
Both A and B
d)
None of the mentioned above
41.
What is the output of the following code snippet?
for l in 'Jhon':
if l == 'o':
pass
print(l, end=", ")
a)
J, h, n,
b)
J, h, o, n,
c)
j,h
d)
h,n
42.
What will be the output of the following code?
my_string = "Python is fun"
print(my_string.isalpha())
a)
True
b)
False
c)
None
d)
Error
43.
What will be the output of the following Python code?
i = 1
while True:
if i%3 == 0:
break
print(i,end = '')
i += 1
a)
1 2 3
b)
Error
65
c)
1 2
d)
none of the mentioned
44.
What will be the output of the following Python code snippet?
for i in [1, 2, 3, 4][::-1]:
print(i, end=' ')
a)
4 3 2 1
b)
Error
65
c)
1 2 3 4
d)
none of the mentioned
45.
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]
46.
Which of the following Python statements will result in the output: 6?
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
a)
A[2][1]
b)
A[1][2]
c)
A[3][2]
d)
A[2][3]
47.
What will be the output of the following Python code?
x = 'abcd'
for i in range(len(x)):
print(i, end = ‘ ’)
a)
error
b)
1 2 3 4
c)
a b c d
d)
0 1 2 3'
48.
What will be the output of the following code snippet?
example = ["Sunday", "Monday", "Tuesday", "Wednesday"];
del example[2]
print(example)
a)
.['Sunday', 'Monday', 'Tuesday', 'Wednesday']
b)
.['Sunday', 'Monday', 'Wednesday']
c)
.['Monday', 'Tuesday', 'Wednesday']
d)
.['Sunday', 'Monday', 'Tuesday']
49.
What will be the output?
numbers = [1, 2, 3, 4]
numbers.append([5,6,7,8])
print(len(numbers))
a)
4
b)
5
c)
8
d)
1
50.
What will be the value of the following Python expression?
4 + 3 % 5
a)
7
b)
2
c)
4
d)
1
51.
What method in Python is used to add an element to the end of a list?
a)
add()
b)
insert()
c)
append()
d)
extend()
52.
What will be the output of the following code snippet?
my_list = [1, 2, 3]
my_list.append(4)
print(my_list)
a)
[1, 2, 3, 4, 5]
b)
[1, 2, 3, 4]
c)
[1, 2, 3]
d)
[4]
53.
What is the output of the following code snippet?
my_list = [1, 2, 3, 4, 5]
my_list.remove(3)
print(my_list)
a)
[1, 2, 4, 5]
b)
[1, 2, 3, 4, 5]
c)
[1, 2, 3, 5]
d)
[1, 2, 4]
54.
What does the extend() method do in Python?
a)
Adds an element to the end of a list
b)
Adds multiple elements to a list
c)
Removes an element from a list
d)
Deletes the entire list
55.
What is the output of the following code snippet?
my_list = [1, 2, 3]
my_list.insert(1, 4)
print(my_list)
a)
[1, 4, 2, 3]
b)
[1, 2, 4, 3]
c)
[1, 2, 3, 4]
d)
[4, 2, 3]
56.
Which list method is used to add multiple elements to the end of a list?
a)
add()
b)
insert()
c)
append()
d)
extend()
57.
Question
What is the output of the following list comprehension?
[char for char in 'hello']
a)
['h', 'e', 'l', 'l', 'o']
b)
['h', 'e', 'l', 'l', 'l', 'o']
c)
['hello']
d)
['h', 'e', 'l', 'l', 'l']
58.
What is the output of the following list comprehension?
[x.upper() for x in ['apple', 'banana', 'cherry']]
a)
['APPLE', 'BANANA', 'CHERRY']
b)
['Apple', 'Banana', 'Cherry']
c)
['a', 'b', 'c']
d)
['apple', 'banana', 'cherry']
59.
What will be the output of the following code snippet?
print(2**3 + (5 + 6)**(1 + 1))
a)
129
b)
8
c)
121
d)
None
60.
What will be the datatype of the var in the below code snippet?
var = 10
print(type(var),end = ' and ')
var = "Hello"
print(type(var))
A
a)
. str and int
b)
. int and int
c)
. str and str
d)
. int and str
61.
What will be the output of the following code snippet?
a = [1, 2, 3]
a = tuple(a)
a[0] = 2
print(a)
a)
[2, 2, 3]
b)
(2, 2, 3)
c)
(1, 2, 3)
d)
Error.
62.
What will be the output of the following code snippet?
print(type(5 / 2))
print(type(5 // 2))
a)
float and int
b)
int and float
c)
float and float
d)
. int and int
63.
What will be the output of the following code snippet?
a = [1, 2, 3, 4, 5]
sum = 0
for ele in a:
sum += ele
print(sum)
a)
15
b)
0
c)
20
d)
None
64.
What will be the output of the following code snippet?
a = 3
b = 1
print(a, b, end = ' ')
a, b = b, a
print(a, b)
a)
. 3 1 1 3
b)
. 3 1 3 1
c)
. 1 3 1 3
d)
. 1 3 3 1
65.
What will be the output of the following code snippet?
a = [1, 2]
print(a * 3)
a)
Error
b)
. [1, 2]
c)
[1, 2, 1, 2]
d)
[1, 2, 1, 2, 1, 2]
66.
What will be the output of the following code snippet?
word = "Python Programming"
n = len(word)
word1 = word.upper()
word2 = word.lower()
converted_word = ""
for i in range(n):
if i % 2 == 0:
converted_word += word2[i]
else:
converted_word += word1[i]
print(converted_word)
a)
pYtHoN PrOgRaMmInG
b)
Python Programming
c)
python programming
d)
PYTHON PROGRAMMING
67.
What will be the output of the following code snippet?
a = "4, 5"
nums = a.split(',')
x, y = nums
int_prod = int(x) * int(y)
print(int_prod)
a)
20
b)
45
c)
54
d)
4,5
68.
What will be the output of the following code snippet?
a = [1, 2, 3, 4]
b = [3, 4, 5, 6]
c = [x for x in a if x not in b]
print(c)
a)
[1, 2]
b)
[5, 6]
c)
[1, 2, 5, 6]
d)
[3, 4]
69.
What will be the result of the following expression in Python “2 ** 3 + 5 ** 2”?
a)
65536
b)
33
c)
169
d)
None of these
70.
What will be the output of the following code snippet?
count = 0
while(True):
if count % 3 == 0:
print(count, end = " ")
if(count > 15):
break;
count += 1
a)
0 1 2 ….. 15
b)
Infinite Loop
c)
0 3 6 9 12 15
d)
0 3 6 9 12
71.
What will be the output of the following Python code?
i = 1
while True:
if i%3 == 0:
break
print(i,end = ' ')
i += 1
a)
1 2 3
b)
error
c)
1 2
d)
none of the mentioned
72.
What are the values of the following Python expressions?
2**(3**2)
(2**3)**2
2**3**2
a)
512, 64, 512
b)
512, 512, 512
c)
64, 512, 64
d)
64, 64, 64
73.
What will be the output of the following Python function?
len(["hello",2, 4, 6])
a)
Error
b)
6
c)
4
d)
3
74.
What will be the output of the following Python code?
x = 'abcd'
for i in x:
print(i.upper(),end = ' ')
a)
a B C D
b)
a b c d
c)
error
d)
A B C D
75.
What will be the output of the following Python code?
print("abc. DEF".capitalize())
a)
Abc. def
b)
abc. def
c)
Abc. Def
d)
ABC. DEF
76.
To add a new element 5 to a list's end we use which Python command?
a)
list1.addEnd(5)
b)
list1.addLast(5)
c)
list1.append(5)
d)
list1.add(5)
77.
Which of the following Python statements will result in the output: 7?
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
a)
A[2][1]
b)
A[1][2]
c)
A[3][2]
d)
A[2][3]
78.
What will be the output of the following Python code?
x = 'abcd'
for i in range(len(x)):
print(i)
a)
error
b)
1 2 3 4
c)
a b c d
d)
0 1 2 3
79.
What will be the output of the following Python expression?
round(4.576)
a)
4
b)
4.6
c)
5
d)
4.5
80.
Which of the following is invalid?
a)
_a = 1'
b)
__a = 1
c)
__str__ = 1
d)
none of the mentioned
81.
Which of the following results in a SyntaxError?
a)
‘”Once upon a time…”, she said.’
b)
“He said, ‘Yes!'”
c)
3\’
d)
”’That’s okay”’
82.
What is the value of average variable of the following Python code snippet?
grade1 = 80
grade2 = 90
average = (grade1 + grade2) / 2
a)
85
b)
85.1
c)
95
d)
95.1
83.
What will be the output of the following Python code?
i = 1
while True:
if i%2 == 0:
break
print(i)
i += 2
a)
1
b)
12
c)
123456…
d)
1357911…
84.
What will be the output of the following Python code?
i = 2
while True:
if i%3 == 0:
break
print(i)
i += 2
a)
246810…
b)
2 4
c)
2 3
d)
error
85.
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 3 0
b)
0 1 2 0
c)
0 1 2
d)
error
86.
What will be the output of the following Python code?
i = 0
while i < 3:
print(i)
i += 1
else:
print(0)
a)
0 1 2 3 0
b)
0 1 2 0
c)
0 1 2
d)
error
87.
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
88.
What will be the output of the following Python code?
x = "abcdef"
i = "i"
while i in x:
print(i, end=" ")
a)
no output
b)
i i i i i i …
c)
a b c d e f
d)
abcdef
89.
What will be the output of the following Python code?
x = "abcdef"
i = "a"
while i in x:
print(i, end = " ")
a)
no output
b)
i i i i i i …
c)
a a a a a a …
d)
a b c d e f
90.
What will be the output of the following Python code?
d = {0: 'a', 1: 'b', 2: 'c'}
for x in d.keys():
print(d[x], end = " ")
a)
0 1 2
b)
a b c
c)
0 a?1 b?2 c
d)
none of the mentioned
91.
What will be the output of the following Python code?
string = "my name is x"
for i in string:
print (i, end=", ")
a)
m, y, , n, a, m, e, , i, s, , x,
b)
m, y, , n, a, m, e, , i, s, , x
c)
my, name, is, x,
d)
error
92.
What will be the output of the following Python code?
string = "my name is x"
for i in string.split():
print (i, end=", ")
a)
m, y, , n, a, m, e, , i, s, , x,
b)
m, y, , n, a, m, e, , i, s, , x
c)
my, name, is, x,
d)
error
93.
Given a string S = ”hello”, what is the output of S.count(‘l’)?
a)
2
b)
1
c)
None
94.
What will be the output of the following Python statement?
print(chr(ord('b')+1))
a)
a
b)
b
c)
c
d)
A
95.
What will be the output of the following code?
sentence = "Python is fun!"
print(sentence[::-1])
a)
"Python is fun!"
b)
"!nuf si nohtyP"
c)
"!nuF si nohtyP"
d)
"nuf si nohtyP!"
Reset
