Question

A Python function get_element(arr, index) is supposed to return the element at a given index. def get_element(arr, index):     # Assume arr is a list of integers     if index >= 0 and index         return arr[index]     else:         return None If arr = [10, 20, 30] and get_element(arr, 3) is called, what will be the outcome, and what is the most direct fix for the logical error in the if condition to prevent an IndexError for valid indices?

A Returns None; change index <= len(arr) to index < len(arr).
B Returns None; change index <= len(arr) to index <= len(arr) - 1.
C Raises IndexError; change index <= len(arr) to index < len(arr).
D Raises IndexError; change index <= len(arr) to index > len(arr) - 1.
E Returns 30; no bug in the condition.
Practice Next

Hey! Ask a query