176k views
0 votes
What is the missing line of code?

>>> phrase = "You are amazing!"
>>> _____
'u a'

phrase[3:6]

phrase[2:6]

phrase[3:5]

phrase[2:5]

User Boxi
by
4.3k points

1 Answer

4 votes

Answer:

phrase[2:5]

Step-by-step explanation:

Given:

The code fragment

Required

The missing line of code

From the question, we understand that the missing line is to return 'u a'

The first character is u.

So, we need to get its index in the phrase variable

u is at index 2

The next character after u is a blank, and it is at index 3

The next after the blank is character a and a is at index 4

To return a sub string from a string in python, the following syntax can be used.

string[start:stop+1]

From the analysis above;

start = 2 i.e index of u

stop = 4 i.e index of a

and the string variable is phrase

So, the instruction that returns 'u a' is:

phrase[2:4+1] or phrase[2:5]

User Winters
by
4.5k points