0% found this document useful (0 votes)
2 views

set2

This document contains a set of multiple-choice questions (MCQs) on Python programming, along with an answer key. Each question tests various aspects of Python, including data types, string formatting, and control flow. The answer key provides the correct answers and explanations for selected questions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

set2

This document contains a set of multiple-choice questions (MCQs) on Python programming, along with an answer key. Each question tests various aspects of Python, including data types, string formatting, and control flow. The answer key provides the correct answers and explanations for selected questions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

MCQ and Answer Key on Python Programming (Set 2)

1. Which of the following is incorrect?


a) float(‘nan’)
b) float(‘inf’)
c) float('123'+'4')
d) float('123+4')
2. Find output:
'{a},{0},{x}'.format(123,a=1.2,x=[1,2,3])
a) '1.2,123,[1, 2, 3]'
b) '123,[1, 2, 3], 1.2'
c) None
d) error

3. Find Output:
s1='%s : %s & %s'
s1%('Delhi','Gurgaon','Noida')

a) 'Delhi’ : ‘Gurgaon’ & ‘Noida'


b) 'Delhi : Gurgaon & Noida'
c) Error
d) None

4. Find Output:
print('there are %d %ss' %(3,'boy'))

a) 'there are %d %ss'


b) 'there are 3 boys'
c) there are 3 boy
d) there are 3 boys

5. Find Output:
bin(10-2) + bin(12^4)

a) '0b10000b1000'
b) 0b10000b1000
c) Error
d) None

6. what is the type of inf?


a) int
b) float
c) string
d) None
7. Find Output:
s={1,2}
s1 = {3,4}
s2 = s + s1
print(s2)

a) error
b) {1,2,3,4}
c) set()
d) None

8. Find Output:
t1 = (3,'abc',[1,2,3])
t2 = t1 * 2
print(t2)

a) 3,'abc',[1,2,3]
b) 3,'abc',[1,2,3], 3,'abc',[1,2,3]
c) (3, 'abc', [1, 2, 3], 3, 'abc', [1, 2, 3])
d) None

9. Find Output:
x = [1,2,'A',(3,4),[5],{6,7},{'y':8}]
print(len(x))

a) 6
b) 7
c) 8
d) None

10. Find Output


n = 10
n<<=2
print(n)

a) 10
b) 20
c) 40
d) None

11. Find Output:


print(bool('bool'),bool(''))

a) False False
b) False True
c) True False
d) True True

12. Find Output:


def func(n):
return n+n,n-n,n*n,n/n
func(10)

a) 20, 0, 100, 1.0


b) (20, 0, 100, 1.0)
c) 20, 0, 100, 1
d) None

13. Find Output:


a=["Bennett","Bennett"]
"University".join(a)

a) 'BennettUniversityBennettUniversity'
b) 'BennettUniversityBennett'
c) BennettUniversityBennett
d) None

14. Find Output:


s = 'bennett university'
s.capitalize()

a) 'Bennett University'
b) 'Bennett university'
c) 'BENNETT UNIVERSITY'
d) None

15. Find Output:


a = [10,11]
b = ['ab','cd']
c = [1.2]
for i in a:
for j in b:
for k in c:
print(i,j,k, end = " ")

a) 10 ab 1.2 10 cd 1.2 11 ab 1.2 11 cd 1.2


b) 10 ab 10 cd 11 ab 1.2 11 cd 1.2
c) 10 ‘ab’ 1.2 10 ‘cd’ 1.2 11 ‘ab’ 1.2 11 ‘cd’ 1.2
d) None

16. What are the two main types of functions in Python?


a) System function
b) Custom function
c) Built-in function & User defined function
d) User function

17. Find Output


def addItem(listParam):
listParam += [1]
print(listParam)

mylist = [1, 2, 3, 4]
addItem(mylist)
print(len(mylist))

a) [1, 2, 3, 4, 1]
5
b) [1, 2, 3, 4]
4
c) [2, 3, 4, 5]
4
d) None

18. Find Output:


z=set('abc$de')
'a' in z

a) False
b) True
c) error
d) None

19. Find Output:


x = ['ab', 'cd']
for i in x:
y = i.upper()
print(y, end=" ")
print(x)

a) AB CD ['ab', 'cd']
b) Ab Cd ['ab', 'cd']
c) ab cd ['ab', 'cd']
d) None

20. Find Output:


i=5
while True:
if i%0O11 == 0:
break
print(i,end=" ")
i += 1

a) 5 6 7 8 9 10
b) 5 6 7 8
c) 5 6
d) error

21. Find Output:


i=1
while False:
if i%2 == 0:
break
print(i)
i += 2

a) 1
b) 1 3 5 7 …
c) 1 2 3 4 …
d) none of the mentioned

22. Find Output:


True = False
while True:
print(True)
break
a) True
b) False
c) Syntax Error
d) None

23. Find Output:


x = "abcdef"
i = "i"
while i in x:
print(i, end=" ")

a) No output
b) a
c) i
d) None

24. Find Output:


x = "abcdef"
i = "a"
while i in x:
x = x[:-1]
print(i, end = " ")

a) i i i i i i
b) a a a a a a
c) a a a a a
d) none of the mentioned

Answer Key
1 – d, [Explanation: ValueError : could not convert string to float : When a numeric string
contains a + or other delimiters/special- characters, it can’t be converted to float]
2–a
3 – b [Explanation: 'Delhi : Gurgaon & Noida']
4–d
5 – a [1st part : bin(10-2) => 8 => 1000 i.e., 0b1000 And 2nd part : bin(12^4) => (1100 xor 01
00) => 1000 i.e., 0b1000 Therefore, ‘0b1000’ + ‘0b1000’ => ‘0b10000b1000’]
6–b
7- a [Explanation: TypeError: unsupported operand type(s) for +: 'set' and 'set']
8–c
9–b
10 – c
11 – c
12 – b
13- b
14 – b
15 – a
16 – c
17 - a
18 – b
19 – a [Hints : in y the output of upper() will be stored but not in x]
20 - b [Hints : 0O11 is equivalent to 3]
21 – d [ Explanation: the loop will not be activated]
22 – c [Explanation: True can’t be used as identifier]
23 – a
24 – b [Explanation: in every pass of the loop the string length is decreasing]

You might also like