135k views
2 votes
Using only a single operation, modify the list stored in 'ham' by concatenating it to the back of a list containing the even integers between 8 and 96 (inclusive).

A) ham.append(list(range(8, 97, 2)))
B) ham.extend(list(range(8, 97, 2)))
C) ham += list(range(8, 97, 2))
D) ham.concat(list(range(8, 97, 2)))
Please select the correct option.

1 Answer

3 votes

Final answer:

The correct answer is option B, which uses the 'extend' method to concatenate a list of even integers between 8 and 96 inclusive to the back of the 'ham' list.

Step-by-step explanation:

The student is required to perform a single operation to concatenate a list of even integers between 8 and 96 to the back of an existing list named 'ham'. To do this correctly, one must use a method that extends the original list with the elements from the new list rather than append a single element which would be the entire new list itself.

The correct option is B) ham.extend(list(range(8, 97, 2))). This method takes each element from the new list (even numbers from 8 to 96) and adds it to the end of the 'ham' list.

Option A would append the whole list as a single element, option C would work but is not considered a method, and option D does not exist in Python. Thus, only option B correctly performs the desired single operation.

User Brendan Kidwell
by
7.4k points