Check your understanding of the previous reading: importing standard-library and third-party functions, and the Drafter web-app library.

Question 1

Which of the following statements are true about importing? Select every one that is true.

Select every option that is true, then check.

  • Correct. Third-party libraries like Drafter are not part of the standard library; they come from a separate repository such as PyPI and must be installed before they can be imported.
  • Not quite. The reading's calculate_area example calls the imported floor function right inside a function you define. Imported functions work like any other function.
  • Not quite. The same calculate_area example reads the imported pi variable from inside a function you define.
  • Not quite. Standard-library and well-established third-party functions are already tested by their maintainers; you don't need to re-verify them yourself before using them.
  • Not quite. The reading's whole point is the opposite: importing greatly increases the capabilities available to you without having to reimplement things like random number generation yourself.

Question 2

Which of the following Drafter functions or components shown in the reading can be used to create or style page content? Select every one that is.

Select every option that comes from Drafter and shapes what a page shows, then check.

  • Correct. bold styles its text argument, as in the reading's "Bolder Text" section.
  • Correct. italic is one of the styling functions introduced in "Composing Functions".
  • Correct. change_color changes the color of its text argument, also from "Composing Functions".
  • Correct. Page creates the web page with the specified content; every route in the reading returns one.
  • Correct. Div is a component that arranges its children in a line, used in "Multiple Lines of Content".
  • Not quite. randint comes from the standard library's random module, from earlier in this same reading; it has nothing to do with Drafter or page content.
  • Not quite. floor comes from the math module, used earlier in this reading to compute an area; it does not create or style page content.

Question 3

Which of the following function calls use Drafter functions in ways demonstrated in the reading? Select every one that is.

Select every call that matches how the reading actually uses that function, then check.

  • Correct. bold takes a single piece of text to style, exactly as in "Bolder Text".
  • Correct. italic also takes a single piece of text, as used in "Multiple Lines of Content".
  • Correct. change_color takes the text first and the color second, matching "Composing Functions".
  • Correct. This is the exact call from "Multiple Lines of Content".
  • Not quite. In the reading, bold is only ever called with a single argument; a color is not part of how it's demonstrated.
  • Not quite. The reading always calls change_color with both the text and the color; a single argument doesn't match that.

Question 4

True or False: will the following code create a Drafter site whose custom page displays the text "Welcome!" in bold?

from drafter import *

@route
def index() -> Page:
    return Page(bold("Welcome!"))

start_server()

Select one answer, then check.

  • Correct. This is exactly the "Bolder Text" example: a route decorated with @route that returns a Page wrapping bold("Welcome!").
  • Not quite. This follows the exact pattern from the reading: a @route function returning Page(bold(...)), with start_server() called at the end.

Question 5

Why will the following route display "Welcome!" as regular text instead of bold text?

from drafter import *

@route
def index() -> Page:
    bold("Welcome!")
    return Page("Welcome!")

start_server()

Select one answer, then check.

  • Not quite. "Bolder Text" passes bold(...) straight to Page, with no Div involved.
  • Correct. Calling bold("Welcome!") on its own line does nothing with its result; the return statement builds its own, separate, unstyled string to hand to Page.
  • Not quite. "Simple Drafter Site" returns Page("Welcome to my Drafter site!") with a plain string, so this works fine.
  • Not quite. Every example places @route above the def line, exactly as it is here.
  • Not quite. Every example calls start_server() last, after the route is defined, just like here.

Question 6

According to the simplest Drafter example in the reading, which of the following are required for that minimum program? Select every one that is required.

Select every option the simplest example actually contains, then check.

  • Correct. Even the simplest example, "Drafter Example", starts by importing the module.
  • Correct. "Drafter Example" is only two lines: the import, and a call to start_server().
  • Not quite. The simplest example has no route at all; routes only appear starting with "Simple Drafter Site", which customizes the default page.
  • Not quite. Page only shows up once a route is defined; the simplest example has neither.
  • Not quite. Div only appears once content has multiple parts to arrange, much later than the simplest example.
  • Not quite. Tests are optional and only appear in "Drafter Tests", well past the simplest example.