Embercode
✕
ConditionalsQuick quiz

Switch

8 questions. Covers Shared cases in match with no fall-through.

Questions 1 to 5 of 8

  1. 1. What does this program print? ``python level = 2 out = "" match level: case 1: out += "a" case 2: out += "b" case 3: out += "c" case _: out += "d" print(out) ``
  2. 2. What does this program print? ``python def code(s): match s: case "start" | "begin": return 1 case "stop": return 2 case _: return 0 print(code("begin") + code("STOP") + code("stop")) ``
  3. 3. This function returns the first level perks from a list. What does this program print? ``python PERKS = ["email support", "extra storage", "priority support"] def perks_for(level): if level in (1, 2, 3): return PERKS[:level] return [] print(len(perks_for(2))) ``
  4. 4. What does Light["BLUE"] do when Light has no member named BLUE? ``python from enum import Enum, auto class Light(Enum): RED = auto() YELLOW = auto() GREEN = auto() print(Light["BLUE"]) ``
  5. 5. What does this program print? ``python from enum import Enum, auto class Light(Enum): RED = auto() YELLOW = auto() GREEN = auto() def action(light): match light: case Light.RED: print("stop") case Light.GREEN: print("go") action(Light.YELLOW) print("program went on") ``

5 question(s) left on this page.