Skip to main content
Module 1 · Learning to Drive

Lesson 1-11 · Python Functions — Knowledge Checks

Name Date
  1. Which keyword defines a function in Python?

    1. A.function
    2. B.def
    3. C.define
    4. D.func

    Answer Why?

  2. Given def square(side_length):, what does calling square(45) make the robot do?

    1. A.Draw a square with 45 cm sides
    2. B.Draw a square with 90 cm sides
    3. C.Turn 45 degrees
    4. D.Cause an error — you must pass two numbers

    Answer Why?

  3. A variable created inside a function (like angle above) can be used…

    1. A.Anywhere in the program
    2. B.Only inside that function — it is local
    3. C.Only after the program ends
    4. D.Only in other functions

    Answer Why?

  4. If a function's variables are local, how can square() use drivetrain, which was created in the main program?

    1. A.Because drivetrain is special to XRPLib
    2. B.When a name is not local, Python looks outside the function for it — functions can read names from the surrounding program
    3. C.It does not work; that program has a bug
    4. D.Because drivetrain is passed in automatically

    Answer Why?

  5. What's wrong with this? def multiply(x, y)

    1. A.multiply should be capitalized
    2. B.It is missing the colon: def multiply(x, y):
    3. C.x and y need quotes
    4. D.Nothing is wrong

    Answer Why?

  6. Given this definition, what does calling polygon(6) draw?

    def polygon(sides, side_length=30):
    1. A.A hexagon with 30 cm sides
    2. B.A hexagon with 6 cm sides
    3. C.A 30-sided shape
    4. D.An error — polygon needs two arguments

    Answer Why?