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

MCQs

The document contains multiple choice and short answer questions related to Python programming concepts, including problem-solving steps, data types, operators, functions, and algorithms. Each question is followed by the correct answer. The content serves as a quiz or study guide for individuals learning Python.
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)
18 views

MCQs

The document contains multiple choice and short answer questions related to Python programming concepts, including problem-solving steps, data types, operators, functions, and algorithms. Each question is followed by the correct answer. The content serves as a quiz or study guide for individuals learning Python.
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

Multiple choice questions

1. What are the basic steps in problem solving?


A) Execution, Debugging, Testing
B) Analyzing the problem, developing an algorithm, coding, testing and debugging
C) coding, analysis, testing, debugging
D) debugging, coding, testing, analyzing
Answer: B) Analyzing the problem, developing an algorithm, coding, testing and debugging

2. Which of the following is a representation of an algorithm using graphical symbols?


A) pseudo code
B) Flowchart
C) Python code
D) variable
Answer: B) Flowchart

3. What is the purpose of comments in Python code?


A) To add logic to the program
B) making the code more confusing
C) to explain the code to other programmers
D) To hide the code from others
Answer: C) to explain the code to other programmers

4. Which data type is used to store a single character in Python?


A) integer
B) string
C) character
D) four
Answer: B) string

5. Which operator checks whether an element is present in a sequence or not?


A) membership operator
B) identity operator
C) assignment operator
D) relational operator
Answer: A) membership operator

6. What is the purpose of break statement in a loop?


A) to continue to the next iteration of the loop
B) premature exit from the loop
C) leaving the loop completely

129
D) repeating the loop indefinitely
Answer: B) premature exit from the loop

7. Which built-in function is used to find the length of a string in Python?


A) size()
B) length()
C) count()
D) len()
Answer: D) len()

8. What is the output of the following Python code?


x=5
you = 2
result = x/y
print(result)

A) 7
B) 2.5
C) 2
D) error
Answer: B) 2.5

9. Which of the following is an example of mutable data type in Python?


A) string
B) integer
C) list
D) tuple
Answer: C) list

10. What is the purpose of the range() function in the for loop in Python?
A) Generating a sequence of numbers
B) performing mathematical operations
C) Checking membership in a list
D) Calculating the factorial of a number
Answer: A) Generating a sequence of numbers

11. Which of the following is not a valid Python variable name?


A) my_variable
B) 123_variable
C) _variable
D) Variable123

130
Answer: B) 123_variable

12. Which operator is used to check whether two values are equal in Python?
A) ==
B) !=
C) <=
D) >
Answer: A) ==

13. What is the result of the expression 5%2 in Python?


A) 2
B) 2.5
C) 0.5
D) 1
Answer: D) 1

14. What does the strip() method do for a string in Python?


A) Removes all the vowels from the string
B) Removes leading and trailing spaces from the string
C) Converts the string to uppercase
D) splits the string into a list
Answer: B) Removes leading and trailing spaces from the string

15. Which of the following is a logical operator in Python?


A)+
B) %
C) and
D) >
Answer: C) and

16. What does the input() function do in Python?


A) displays the output on the screen
B) accepts input from the user
C) performs mathematical calculations
D) converts data types
Answer: B) accepts input from the user

17. Which of the following statements will create a list?


A) L = list()
B) L = []
C) L = list([1, 2, 3])

131
D) All of the above
Answer: D) All of the above

18. What is the output when we execute a list("hello")?


A) ['h', 'e', 'l', 'l', 'o']
B) ['hello']
C) ['llo']
D) ['olleh']
Answer: A) ['h', 'e', 'l', 'l', 'o']

19. Suppose L is [5, 3, 9, 4], what is max(L)?


A) 5
B) 3
C) 9
D) 4
Answer: C) 9

20. Suppose L is [5, 3, 9, 4], what is min(L)?


A) 5
B) 3
C) 9
D) 4
Answer: B) 3

21. Suppose L is [5, 3, 9, 4], what is sum(L)?


A) 5
B) 3
C) 9
D) 21
Answer: D) 21

22. Suppose L is [2, 3, 8, 4, 5], What is L[-1]?


A) 2
B) 5
C) 8
D) 4
Answer: B) 5

23. Suppose L is [2, 3, 8, 4, 5], What is L[:-1]?


A) [2, 3, 8, 4, 5]
B) [2, 3, 8, 4]

132
C) [5, 4, 8, 3, 2]
D) [4, 8, 3, 2]
Answer: B) [2, 3, 8, 4]

24. Which of the following is a Python tuple?


A) [1, 2, 3]
B) (1, 2, 3)
C) {1, 2, 3}
D) {}
Answer: B) (1, 2, 3)

25. If 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) T[3] = 45

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


>>>T = (1, 2)
>>>2 * T
A) (1, 2, 1, 2)
B) [1, 2, 1, 2]
C) (1, 1, 2, 2)
D) [1, 1, 2, 2]
Answer: C) (1, 2, 1, 2)

27. Write the output of the following code?


>>> L1=[1,55,100,6,453,2,66,23,56]
>>> L2=sorted(L1)
>>> L2
A) [1, 2, 6, 23, 55, 56, 66, 100, 453]
B) [1, 55, 100, 6, 453, 2, 66, 23, 56]
C) []
D) Error
Answer: A) [1, 2, 6, 23, 55, 56, 66, 100, 453]

28. Which method deletes the last inserted (key, value) pair from the dictionary?
A) pop()
B) popitem()

133
C) del()
D) del
Answer: B) popitem()

29. _______________ is a mapping of unique keys to values. It consists of key-values pairs.


A) List
B) Dictionary
C) String
D) Tuple
Answer: B) Dictionary

30. Write output of the following code in interactive mode/shell?


>>> dict1={'Student': (1, 'Sachin', 'Computer'), 'Teacher': ('Hindi', 1001, 'Saanvi')}
>>> dict1["Teacher"][2]
A) ‘Sachin’
B) ‘Hindi’
C) ‘Saanvi’
D) ‘Teacher
Answer: C) ‘Saanvi’

31. To include the use of functions which are present in the random library, we must use the
option:
A) import random
B) random.h
C) import.random
D) random.random
Answer: A) import random

32. What can be the output of the following Python code?


random.randrange(1,100,10)
A) 32
B) 67
C) 91
D) 80
Answer: D) 80

Short Answer Questions


1. Define the term algorithm.
Answer: An algorithm is a step-by-step procedure for performing a specific task.

134

You might also like