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

COMPUTER PROGRAMMING PYTHON MCQ

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

COMPUTER PROGRAMMING PYTHON MCQ

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

COMPUTER PROGRAMMING PYTHON –BCSE101E

CAT 1 QUESTIONS

MCQ QUESTIONS

1. Suppose t = (1, 2, 4, 3), which of the following is incorrect?


a) print(t[3])
b) t[3] = 45
c) print(max(t))
d) print(len(t))
Answer: b

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


t=(1,2,4,3)
print(t[1:-1])
a) (1, 2)
b) (1, 2, 4)
c) (2, 4)
d) (2, 4, 3)
Answer: c

3. Choose the correct option with respect to Python.


a) Both tuples and lists are mutable.
b) Both tuples and lists are immutable.
c) Tuples are immutable while lists are mutable.
d) Tuples are mutable while lists are immutable.
Ans :- C

4. Is the following Python code valid?


>>> a,b=1,2,3
a) No, too many values to unpack
b) Yes, this is an example of tuple unpacking. a=1 and b=2
c) Yes, this is an example of tuple unpacking. a=1 and b=(2,3)
d) Yes, this is an example of tuple unpacking. a=(1,2) and b=3
Ans :- A

5. Which of the following is invalid?


a) _a = 1
b) __a = 1
c) __str__ = 1
d) none of the mentioned
Answer: D

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


>>> a=(1,2)
>>> b=(3,4)
>>> c=a+b
>>> c
a) (4,6)
b) (1,2,3,4)
c) Error as tuples are immutable
d) None
Ans :- B

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


d = {"john":40, "peter":45}
d["john"]
a) 40
b) 45
c) “john”
d) “peter”
Ans :- A

8. What is the output of the line of code shown below, if s1= {1, 2, 3}?
s1.issubset(s1)
a) True
b) False
c) Error
d) No output
Ans :- A

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


>>> a=(1,2,3,4)
>>> del(a[2])
a) Now a=(3,4)
b) Now, a=(1,2,4)
c) Now, a=(1,3,4)
d) Error as tuple is immutable
Ans :- D

10. Which of the following is not used as loop in Python?


a) for loop
b) while loop
c) do-while loop
d) None of the above
Ans :- C

11. Which one of the following is a valid Python if statement :


a) if a>=2
b) if (a >= 2)
c) if (a => 22)
d) if a >= 22
Ans :- A

12. Which of following is not a decision-making statement.


a) if statement
b) if-elif statement
c) for statement
d) if -else statement
Ans :- C

13. Point out the correct statement?


a) Break will execute a loop while a condition is true
b) The if/else statement conditionally evaluates two statements
c) Blocks are evaluated until a new line is entered after the closing brace
d) Single statements are evaluated when a new line is typed at the start of the syntactically
complete statement
Ans :- B

14. Which of the following is a valid for loop in Python?


a) for i in range(5)
b) for i in range(0,5)
c) for(i=0; i < n; i++)
d) for i in range(0,5):
Ans :- D

15. Does python have switch case statement?


a) True
b) False
c) Python has switch statement but we can not use it.
d) None of the above
Ans :- B

16. What is the output of the following assignment operator


y = 10
x = y += 2
print(x)
a) 10
b) 12
c) SynatxError
d) none
Ans :- C

17. Which of the following statements create a dictionary?


a) d = {}
b) d = {40:”john”, 45:”peter”}
c) d = {“john”:40, “peter”:45}
d) All of the mentioned
Ans :- D

18. Which of the following is not a declaration of the dictionary?


a) { }
b) {1,”A”,2”B”}
c) {1: ‘A’, 2: ‘B’}
d) dict([[1,”A”],[2,”B”]])
Ans :- B

19. Which of the statements about dictionary values if false?


a) Values of a dictionary must be unique
b) More than one key can have the same value
c) The values of the dictionary can be accessed as dict[key]
d) Values of a dictionary can be a mixture of letters and numbers
Ans :- A

20. If a is a dictionary with some key-value pairs, what does a.popitem() do?
a) Removes an arbitrary element
b) Invalid method for dictionary
c) Removes all the key-value pairs
d) Removes the key-value pair for the key given as an argument
Ans :- A

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


tuple1=(5,1,7,6,2)
tuple1.pop(2)
print(tuple1)
A. Error
B. (5,1,6,2)
C. (5,1,7,6)
D. (5,1,7,6,2)
Ans :- A

You might also like