1.
Q1: The following function is intended to return a string formed by concatenating elements from the parameter
words
. The elements to be concatenated start with start_index
and continue through the last element of words
and should appear in reverse order in the resulting string.
# Assume len(words) > 0 and start_index >= 0
def concat_words(words, start_index):
result = ""
# missing code
return result
For example, the following code segment should print CarHouseGorilla:
things = ["Bear", "Apple", "Gorilla", "House", "Car"]
print(concat_words(things, 2))
Which of the following code segments is a correct replacement for
# missing code
?
I.
for k in range(start_index, len(words)):
result += words[k] + words[len(words) - k - 1]
II.
k = len(words) - 1
while k >= start_index:
result += words[k]
k -= 1
III.
temp = words.copy()
temp.reverse()
for k in range(len(temp) - start_index):
result += temp[k]
- I only
- II only
- III only
- I and II only
- II and III only