Embercode
✕
Pattern PrintingQuick quiz

Triangles

8 questions. Covers Floyd's triangle with Python loops.

Questions 1 to 5 of 8

  1. 1. What does this program print? ``python def next_row(prev): nxt = [1] for i in range(len(prev) - 1): nxt.append(prev[i] + prev[i + 1]) nxt.append(1) return nxt row = [1] for _ in range(4): row = next_row(row) print(row) ``
  2. 2. What is the last line printed? ``python def choose(n, k): result = 1 for i in range(k): result = result * (n - i) // (i + 1) return result print(choose(12, 4)) print(choose(6, 2)) ``
  3. 3. What does this program print? ``python def find_position(target): row = 1 first_of_row = 1 while first_of_row + row - 1 < target: first_of_row += row row += 1 column = target - first_of_row + 1 return row, column row, column = find_position(20) print(f"20 is in row {row}, column {column}") ``
  4. 4. The Floyd's triangle program prints each number with print(next_number, end=""). Which keyword argument of print stops it from adding a line break? Give the name only.

    Type your answer.

  5. 5. The counter in Floyd's triangle is not named next. Which built-in function would that name hide? Give the name only.

    Type your answer.

5 question(s) left on this page.

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