Embercode
✕
Object-Oriented ProgrammingQuick quiz

Factory and enums

8 questions. Covers Enums with fields in Python.

Questions 1 to 5 of 8

  1. 1. What does this code print? The enum is the CoffeeSize from this lesson, with LARGE = ("L", 480, 350). ``python print(CoffeeSize.from_code("l").price_text()) print(CoffeeSize.from_code("XL") is None) ``
  2. 2. In the Color factory methods from this lesson, rgb ends with return cls(red, green, blue) instead of return Color(red, green, blue). Why?
  3. 3. What exception does Python raise for CoffeeSize["HUGE"] when no member has that name?

    Type your answer.

  4. 4. Which expression gives the position of MEDIUM in the list of members, counting from 0?
  5. 5. A programmer adds created = 0 to the body of an enum to count its members. What does list(Level) show? ``python from enum import Enum class Level(Enum): LOW = 1 HIGH = 2 created = 0 print(list(Level)) ``

5 question(s) left on this page.

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