Which index position is returned when the string method .find( ' python ' ) is applied to the string ' learning python programming ' ?
Correct Answer: B
The .find() method returns the lowest index where the searched substring is found. Example: " learning python programming " .find( " python " ) Output: 9 Indexing starts at 0 in Python. In the string ' learning python programming ' , the word ' python ' begins at index 9. Python's built-in types documentation describes str.find() as returning the lowest index where the substring is found. Therefore, the correct answer isB. 9.
Question 17
How does Jupyter Notebook function as a development environment?
Correct Answer: B
Jupyter Notebook works as acell-based interactive coding platform. A notebook is made up of cells, and code can be written and executed inside those cells. For example, a code cell may contain: x = 10 print(x) When the cell is run, the output appears directly below the cell. The Jupyter Notebook documentation explains that notebooks consist of a sequence of cells, and the contents of a cell can be executed using keyboard shortcuts or the toolbar button. Jupyter Notebook is not simply a command-line terminal replacement, not limited to static text editing, and not mainly a framework for compiling Python into standalone applications. Therefore, the correct answer isB. Cell-based interactive coding platform.
Question 18
Which components are required in every Python while loop?
Correct Answer: A
A Python while loop needs a condition and an indented code block. Example: count = 1 while count < = 3: print(count) count += 1 The condition is count < = 3. The indented block contains the code that runs while the condition is true. Python's compound statement documentation includes while as a control-flow statement. Therefore, the correct answer isA. A condition and an indented code block.
Question 19
Which components are required in every Python for loop?
Correct Answer: A
A Python for loop is used to iterate over an iterable object, such as a list, tuple, string, dictionary, set, or range() object. A basic for loop needs: A loop variable An iterable object An indented code block Example: for number in range(3): print(number) In this example: number is the loop variable. range(3) is the iterable. print(number) is the indented code block that runs during each loop iteration. According to the official Python documentation, the for statement is a construct that works with iterable objects. Therefore, the correct answer is A. A variable, an iterable, and an indented code block.
Question 20
A dictionary prices = { ' apple ' : 1.50, ' banana ' : 0.75, ' orange ' : 2.00} needs to have all values increased by 0.25. Which code correctly accomplishes this task?
Correct Answer: A
In Python, iterating directly over a dictionary gives itskeys. In this dictionary, the keys are: ' apple ' ' banana ' ' orange ' To update each price, the program can loop through each key and use that key to access and change the corresponding value. Correct code: prices = { ' apple ' : 1.50, ' banana ' : 0.75, ' orange ' : 2.00} for item in prices: prices[item] = prices[ item] + 0.25 print(prices) Output: { ' apple ' : 1.75, ' banana ' : 1.0, ' orange ' : 2.25} Option B is incorrect because value actually receives each dictionary key, not each dictionary value. Also, assigning to value would not update the dictionary. Option C is incorrect because item is not defined, and the loop structure is invalid for this task.