Python Revision Tour - II - Homework

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

2.

Python Revision Tour-II

1. Which of the following is/are example(s) of logical error?


(a) Identing a block to the wrong level (b) Getting operator precedence wrong
(c) Making a mistake in a boolean expression (d) All of these

2. Which of the following is false?


(a) String is mutable.
(b) capitalize() function in string is used to return a string by converting first character of
the string into uppercase.
(c) lower() function in string is used to return a string by converting the whole given string
into lowercase.
(d) None of the above

3. 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.
4. Which of the following will result in an error?
str1=“hello”
(a) print(str1[1]) (b) str1[2]=“a”
(c) print(str1[0:7]) (d) Both (b) and (c)

5. Syntax error in python is detected by................. at .............. .


(a) compiler, compile time (b) interpreter, run-time
(c) compiler, run-time (d) interpreter, compile time

6. Suppose list1 is [2, 33, 222, 14, 25], what is list1[−1] ?


(a) Error (b) None (c) 25 (d) 2

7. Suppose list1 is [3,5, 25, 1, 3], what is min(list1) ?


(a) 3 (b) 5 (c) 25 (d) 1

8. Which of the following option will not result in an error when performed on tuple in
Python, where tup1=(5, 6, 8, 9)?
(a) tup1[1]=12 (b) tup1.append(2) (c) tup=tup1+tup1 (d) tup1.sort()

9. dic1={“A”:15,“B”:16,“C”:17}
print(dic1[1])
What will be the output of above Python code?
(a) B (b) 16 (c) {“B”:16} (d) Error

10. What will be the output of below Python code?


tup1=(1, 2, 3)
tup=tup1*2
print(tup)
(a) (2,4,6) (b) (1,2,3,1,2,3) (c) (1,1,2,2,3,3) (d) Error

11. Which of the following two Python codes will give same output?
If tup1=(1, 2, 3, 4, 5)
(i) print(tup1[:-1]) (ii) print(tup1[0:5])
(iii) print(tup1[0:4]) (iv) print(tup1[-4:])
(a) i, ii (b) ii, iv
(c) ii, v (d) i, iii

12. What will be the output of the following Python code?


x=[1, 3, 6, [18]]
y=list(x)
x[3][0]=15
x[1]=12
print(y)
(a) [1,3,6, [15]] (b) [1,3,6,[12]] (c) [1,3,15,[18]] (d) [1,12,15,[18]]

13. What will be the output of the following Python code?


num = { }
num[(1,3,5)] = 18
num[(5,3,1)] = 16
num|(1,3)] = 22
sum = 0
for i in num:
sum += num[i]
print(len(num) + sum)
(a) 54 (b) 38
(c) 33 (d) 59

14. What will be the output of following Python code?


list1=[1,2,3,4,5]
str1=“6”
for i in list1:
str1=str1+i
print(str1)
(a) 654321 (b) 123456
(c) 123645 (d) Error

15. What will be the output of following Python code?


dict1={“A”:15,“B”:23,“C”:21}
str1=“ ”
for i in dict1:
str1=str1+str(dict1[i])+“ ”
str2=str1[:−1]
print(str2[::−1])
(a) 12 32 51 (b) 12 32 15 (c) 32 21 15 (d) Error

You might also like