Embercode
✕
StringsQuick quiz

Prefixes

6 questions. Covers Longest common prefix in Python.

Questions 1 to 5 of 6

  1. 1. Using this by_columns function, what does this program print? ``python def by_columns(words): first = words[0] for col in range(len(first)): for word in words: if col >= len(word) or word[col] != first[col]: return first[:col] return first print(by_columns(['ab', 'abc', 'abd'])) ``
  2. 2. Using this by_shortening function, what does this program print? ``python def by_shortening(words): prefix = words[0] for word in words: while not word.startswith(prefix): prefix = prefix[:-1] return prefix print(by_shortening(['interview', 'inter', 'internal'])) ``
  3. 3. What does this program print? ``python word = 'fl' print(word[0:6]) print(word[5]) ``
  4. 4. The function below is the column method without its length check. What happens when you call no_length_check(['abc', 'a'])? ``python def no_length_check(words): first = words[0] for col in range(len(first)): c = first[col] for row in range(1, len(words)): if words[row][col] != c: return first[:col] return first ``
  5. 5. In the check that a word begins with the candidate, the code is word.______(prefix). Write the method name that fills the blank.

    Type your answer.

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.