A Secret Path Is A List Of Length 1 Or Greater That Can Be Followed As Described Below Starting At Index O The Value 1 (146.02 KiB) Viewed 42 times
A Secret Path Is A List Of Length 1 Or Greater That Can Be Followed As Described Below Starting At Index O The Value 2 (33.05 KiB) Viewed 42 times
A Secret Path Is A List Of Length 1 Or Greater That Can Be Followed As Described Below Starting At Index O The Value 3 (45.47 KiB) Viewed 42 times
A "secret path" is a list of length 1 or greater that can be followed as described below. Starting at index o, the value at the current index indicates the next index to move to. The value 'E' indicates that the end of the path has been reached. All values in a secret path are less than the length of the list (ie, all are valid indices). The function can_reach_end (pathway) takes as its only argument the list pathway describing the secret path, and returns True if at least one end 'E' can be reached and False otherwise. For example: >>>_can_reach_end([1, 'E']) True You can follow the secret path [1,'E'] by starting at index o, which leads to index 1, at which point the end of the path 'E' has been reached. >>>can_reach_end ([2, 'E', 0]) False You can follow the secret path [2, 'E', 0] by starting at index o, which leads to index 2, which leads back to index (and so on); thus the end of the path 'E' will never be reached. >>> can_reach_end([1, 2, 1]) False The secret path [1, 2, 1] contains no end 'E'.
As presented, the lines of the function are out of order in the window to the right. Put the lines in the correct order and introduce appropriate indentation. Note that as an additional constraint, your code should not produce any PEP-8 warnings when run.
def _can_reach_end (pathway): if cur_value in seen: cur_value = pathway [0] return False if not pathway: while cur_value != 'E': return True return False seen. add (cur_value) cur_value = pathway [cur_value] seen = {cur_value}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!