Embercode
✕
Functions and ScopeQuick quiz

Parameters in Python

7 questions. Covers Variable-length arguments with *args in Python.

Questions 1 to 5 of 7

  1. 1. The function below is meant to return the middle reading and leave the caller's list alone. The caller passes readings = [9, 2, 7, 4, 5], prints the median, and then prints readings. ``python def median(values): values.sort() return values[len(values) // 2] readings = [9, 2, 7, 4, 5] print(median(readings)) print(readings) `` What is the bug?
  2. 2. What does this program print? ``python def count_items(*items): return len(items) print(count_items([1, 2, 3])) ``
  3. 3. Python has a built-in ordered type that cannot be changed after it is made, and it is often used for a fixed set of values passed to a function. What is its name? Write one word.

    Type your answer.

  4. 4. What happens when this program runs? ``python def show(*items, count): print(count) show(1, 2, 3) ``
  5. 5. What does this program print? ``python class Team: def __init__(self, names): self.members = names names = ["Ana", "Ben"] team = Team(names) names[1] = "Changed" print("team sees:", team.members) ``

5 question(s) left on this page.

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