QUESTION IMAGE
Question
what is the missing line of code?
>> sentence = \programming is fun!\
>>
gr
sentence2:5
sentence2:6
sentence3:5
sentence3:6
Step1: Recall string slicing in Python
In Python, string slicing uses the syntax string[start:stop] where the start index is inclusive and the stop index is exclusive.
Step2: Analyze the target substring "gr"
The letter 'g' is the 3rd character (index 2 as indexing starts at 0) and 'r' is the 4th character (index 3). To get "gr", we need to start at index 2 and stop at index 4. So the correct slicing is sentence[2:4]. But among the given options, sentence[2:5] will also include the next - character after 'r' which is not a problem as long as "gr" is part of it.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
A. sentence[2:5]