Multiple Choice Questions
1. What does the range () function do in Python?
- (a) Generates a list of numbers
- (b) Creates a sequence of numbers
- (c) Calculates the sum of numbers
- (d) Prints a range of numbers
2. What is the output of the below code?
count = 0 for i in range(2): for j in range(3): count += 1 print(count)
- (a) 4
- (b) 5
- (c) 6
- (d) 7
3. Which method is used to add an item at the end of the list in Python?
- (a) insert()
- (b) append()
- (c) add()
- (d) extend()
4. What is the purpose of control structures in programming?
- (a) Only to make code longer
- (b) To manage decision-making and repetition of tasks
- (c) To create variables
- (d) To import libraries
5. Which statement is used to execute code when a condition is false?
- (a) if
- (b) elif
- (c) else
- (d) while
6. How do you prevent print() from adding a newline?
- (a) Use end=" "
- (b) Use newline=False
- (c) Use break
- (d) Use continue
7. Which library is used to generate random numbers?
- (a) Datetime
- (b) statistics
- (c) random
- (d) math
8. What does list.append() do?
- (a) Removes the first item
- (b) Adds an item to the end
- (c) Sorts the list
- (d) Reverses the list
9. What is the purpose of the range() function?
- (a) To create a list of numbers
- (b) To generate a sequence of numbers
- (c) To calculate the range of values
- (d) To sort numbers
10. Which debugging technique involves adding output statements?
- (a) Unit testing
- (b) Print statements
- (c) Error messages
- (d) Integration testing
Short Questions
1. Explain the use of the range() function in for loop?
2. What is the difference between the append and remove methods in Python lists?
3. Define debugging.
4. What are the three parameters of the range() function?
5. Name three list methods and their purposes.