1. Home
  2. Explore
  3. Computer Science
  4. Modularity in Game Development

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Modularity in Game Development

  • 97Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Modular Design
The programming strategy of breaking a large problem into smaller parts is called
.

97 questions

  1. 1
    The programming strategy of breaking a large problem into smaller parts is called
    _____
    .
    Hint

    Think of organizing a complex program into manageable components.

    Answer

    modularity

    Explanation

    Modularity means breaking a large programming problem into smaller components that can be developed separately.

  2. 2
    In a role-playing game, activities such as farming, fishing, mining, and crafting are examples of high-level
    _____
    .
    Hint

    These group related activities before they are split into smaller actions.

    Answer

    categories

    Explanation

    Broad categories organize a game’s functionality before each category is divided into specific tasks.

  3. 3
    Within farming, actions such as planting, watering, and harvesting are examples of smaller
    _____
    .
    Hint

    They are more specific tasks within a broader activity.

    Answer

    sub-problems

    Explanation

    Breaking a category such as farming into actions creates smaller sub-problems that can be tackled individually.

  4. 4
    Modularity lets programmers focus on solving each smaller task in
    _____
    rather than juggling the whole program at once.
    Hint

    The task is handled separately from the rest of the system.

    Answer

    isolation

    Explanation

    A programmer can work on one sub-problem at a time, independently of the larger program.

  5. 5
    If harvesting returns vegetables based on how well a plant was cared for, that is an example of implementing a small
    _____
    .
    Hint

    It is one specific piece of the larger farming system.

    Answer

    sub-problem

    Explanation

    The harvesting behavior is a smaller task than implementing all farming mechanics or an entire game.

  6. 6
    Separate farming and fishing components can be owned by different teams, making modularity helpful for
    _____
    .
    Hint

    Think about multiple programmers working on different parts of a project.

    Answer

    collaboration

    Explanation

    Modular components let teams work on separate areas, reducing the need to coordinate every code change directly.

  7. 7
    When developers work on separate components, they can focus on their tasks with less concern about code
    _____
    .
    Hint

    These can occur when separate contributions interfere with one another.

    Answer

    conflicts

    Explanation

    Separating components helps programmers avoid conflicting with teammates’ code while they work independently.

  8. 8
    Testing small components separately makes it easier to determine whether a particular piece of code works and to
    _____
    .
    Hint

    This is the process of locating and fixing errors.

    Answer

    debug

    Explanation

    A focused test of a small component makes errors easier to identify than testing an entire large program at once.

  9. 9
    Testing individual car components, such as brakes and transmission, illustrates the value of testing software
    _____
    .
    Hint

    The analogy checks parts of a system rather than only testing the whole system.

    Answer

    components

    Explanation

    Like testing car parts individually, software components can be checked separately; working parts increase confidence in the whole system.

  10. 10
    Organizing code by task makes it more readable and easier to find because it is no longer one giant
    _____
    .
    Hint

    The word describes disorganized code that is difficult to navigate.

    Answer

    mess

    Explanation

    Modular organization groups code by functionality, making the program easier to navigate and work with.

  11. 11
    A function is a named block of code that performs a specific
    _____
    .
    Hint

    It describes the purpose the block of code carries out.

    Answer

    task

    Explanation

    A function packages instructions under a name so that a particular task can be performed when needed.

  12. 12
    Defining a function once lets a programmer execute its task repeatedly without rewriting the same code, reducing
    _____
    .
    Hint

    This is what happens when the same instructions are written again and again.

    Answer

    repetition

    Explanation

    A function can be called multiple times, so its instructions do not need to be duplicated throughout a program.

  13. 13
    A function gives a name to a set of instructions in much the same way a variable gives a name to a
    _____
    .
    Hint

    A variable can refer to data stored in a program.

    Answer

    value

    Explanation

    A variable names a value, while a function names a set of instructions for performing a task.

  14. 14
    Values supplied to a function allow its task to be generalized; these inputs are called
    _____
    .
    Hint

    They are passed into a function call.

    Answer

    arguments

    Explanation

    Arguments are the input values supplied when a function is called, allowing it to work with different data.

  15. 15
    The named variables specified in a function definition to receive input values are called
    _____
    .
    Hint

    They correspond to the inputs provided when the function is called.

    Answer

    parameters

    Explanation

    Parameters are variables in the function definition that receive the corresponding argument values.

  16. 16
    In Python, a function definition begins with the keyword
    _____
    .
    Hint

    This keyword is short for “define.”

    Answer

    def

    Explanation

    Python uses the keyword def to introduce a function definition.

  17. 17
    The function name, parentheses, and colon at the start of a definition form the function
    _____
    .
    Hint

    It is the line that introduces the function before its indented body.

    Answer

    header

    Explanation

    The function header contains the definition keyword, function name, parameter parentheses, and colon.

  18. 18
    The indented instructions that perform a function’s task make up its function
    _____
    .
    Hint

    It is the code underneath the function header.

    Answer

    body

    Explanation

    Python identifies the function body by its indentation beneath the function header.

  19. 19
    Parameters behave like variables that are accessible only within the function body; they have local
    _____
    .
    Hint

    This term describes the region where a name can be accessed.

    Answer

    scope

    Explanation

    A parameter is available within its function’s local region, not automatically throughout the program.

  20. 20
    A function uses the keyword
    _____
    to specify the output value it sends back to its caller.
    Hint

    This keyword ends the function’s work and provides a result.

    Answer

    return

    Explanation

    The value following return becomes the output value of the function call.

  21. 21
    A function definition describes how to perform a task, while a function
    _____
    actually performs it.
    Hint

    The program uses the function’s name and parentheses to do this.

    Answer

    call

    Explanation

    Defining a function teaches the computer its instructions; calling the function executes them.

  22. 22
    A function definition must appear before its function calls so the computer has learned the task before it tries to
    _____
    .
    Hint

    The computer cannot perform instructions it has not yet encountered in the program.

    Answer

    execute it

    Explanation

    In the described Python execution model, the definition needs to be processed before the function is called.

  23. 23
    When a function is called, arguments are bound to the corresponding parameters in
    _____
    .
    Hint

    The first supplied input matches the first parameter, and so on.

    Answer

    order

    Explanation

    Arguments are assigned to parameters by position: the first argument goes to the first parameter, and subsequent arguments follow in sequence.

  24. 24
    When a function call finishes, its expression evaluates to the value supplied by the function’s
    _____
    .
    Hint

    It is the instruction that provides the function’s output.

    Answer

    return statement

    Explanation

    The returned value replaces the function-call expression in the surrounding code.

  25. 25
    When the computer first encounters a function definition, it records the instructions but does not yet
    _____
    the function body.
    Hint

    At this point, the computer is learning the task rather than carrying it out.

    Answer

    execute

    Explanation

    Processing a definition makes the function available; the body runs only when the function is called.

  26. 26
    When a function call begins, the computer creates an isolated region of short-term memory called a
    _____
    .
    Hint

    It stores the local state for one function call.

    Answer

    stack frame

    Explanation

    A stack frame is a separate memory area used to hold a function call’s arguments, parameters, and local variables.

  27. 27
    The computer copies each call’s input values into its stack frame and associates them with the corresponding
    _____
    .
    Hint

    These names appear in the function definition.

    Answer

    parameter names

    Explanation

    Arguments are stored in the new frame under the names of their corresponding parameters.

  28. 28
    A function’s return statement transfers execution back to the function’s
    _____
    .
    Hint

    This is the location in the program where the function was called.

    Answer

    call site

    Explanation

    After computing the return value, the computer resumes execution at the line that made the call.

  29. 29
    When a function returns, its stack frame is popped off and its local memory is
    _____
    .
    Hint

    The function’s temporary state does not remain available after it ends.

    Answer

    cleared

    Explanation

    Returning ends that function call, removing its stack frame and its local variables from active memory.

  30. 30
    A returned value can be stored in a variable at the call site, while a returned value that is not used is effectively
    _____
    .
    Hint

    The function computed it, but the program did not save or use it.

    Answer

    lost

    Explanation

    A function call can produce a value without the surrounding code storing it; in that case the result is discarded.

  31. 31
    User-defined function definitions are not remembered across separate program executions, so they must be processed each time the program
    _____
    .
    Hint

    The computer’s memory for one execution does not persist into the next.

    Answer

    runs

    Explanation

    The computer clears its program memory when execution terminates, so it must learn the user-defined functions again on the next run.

  32. 32
    A variable’s scope is the region of a program where that variable can be
    _____
    .
    Hint

    Scope determines where a name can be used.

    Answer

    accessed

    Explanation

    The scope of a variable describes the part of the program in which the variable is available.

  33. 33
    Names defined at the top level of a program are in
    _____
    scope.
    Hint

    This is the program-wide scope outside function-local regions.

    Answer

    global

    Explanation

    Top-level names are stored in global scope and can be accessed from different parts of the program, subject to name lookup rules.

  34. 34
    Variables assigned within a function call are normally stored in the function’s
    _____
    scope.
    Hint

    This scope belongs to a particular function region.

    Answer

    local

    Explanation

    Function parameters and local assignments are stored in the function’s own stack frame, separate from global scope.

  35. 35
    If a function assigns to a local variable with the same name as a global variable, it creates a separate local name rather than automatically overwriting the
    _____
    .
    Hint

    The two names live in different scopes.

    Answer

    global variable

    Explanation

    A local assignment affects the function’s local variable; it does not by itself update a same-named global variable.

  36. 36
    When a function returns, its local variables disappear because the function’s
    _____
    .
    Hint

    The local memory for the completed call is removed.

    Answer

    stack frame is popped

    Explanation

    Popping the stack frame removes the local variables associated with that function call.

  37. 37
    The reliable way for a function to communicate a calculated result back to its caller is through its
    _____
    .
    Hint

    It is the output channel of the function.

    Answer

    return value

    Explanation

    Local assignments do not automatically change global state; a function should return information for the caller to use.

  38. 38
    Python’s global keyword can allow a function to access a global variable explicitly, but good practice is to use it
    _____
    .
    Hint

    The lesson warns against relying on this mechanism in most cases.

    Answer

    rarely

    Explanation

    Changing global state can create naming conflicts and hidden dependencies, so the global keyword should almost never be needed.

  39. 39
    Keeping variables local allows different functions to reuse variable names without requiring every name in the program to be globally
    _____
    .
    Hint

    Local scopes prevent names from colliding across functions.

    Answer

    unique

    Explanation

    Local scope reduces naming conflicts because a name used in one function need not differ from names in unrelated functions.

  40. 40
    When Python cannot find a name in the current local scope, it searches the next closest enclosing scope, such as
    _____
    .
    Hint

    This is the broader scope outside the function.

    Answer

    global scope

    Explanation

    Name lookup starts in the closest scope and proceeds outward to enclosing scopes; a global name can therefore be read if no local name shadows it.

  41. 41
    If name lookup fails in every available scope, Python raises a
    _____
    .
    Hint

    It indicates that the requested name could not be found.

    Answer

    NameError

    Explanation

    Python raises a NameError when it runs out of scopes to search without finding the requested name.

  42. 42
    Passing needed information into a function through parameters avoids hidden dependence on variables in
    _____
    .
    Hint

    This is information outside the function’s local region.

    Answer

    global scope

    Explanation

    Explicit parameters make a function’s requirements clear to its callers and avoid assuming that particular global variables exist.

  43. 43
    When one function calls another, the inner call creates a new stack frame on top of the still-active
    _____
    .
    Hint

    The calling function has not finished executing yet.

    Answer

    outer stack frame

    Explanation

    The computer preserves the caller’s frame while the nested function runs, then resumes the caller after the nested call returns.

  44. 44
    After a nested function returns, the computer removes its top stack frame and resumes the calling function where it
    _____
    .
    Hint

    The outer function’s state is preserved while the inner function runs.

    Answer

    left off

    Explanation

    The outer frame remains intact during the nested call, allowing execution to continue from the point of interruption.

  45. 45
    Each stack frame tracks variables local to a particular function
    _____
    .
    Hint

    A function invoked multiple times receives separate execution state for each one.

    Answer

    call

    Explanation

    A new frame is created on each call, keeping that call’s local variables separate from other calls.

  46. 46
    A long function that calculates footstep volume, adjusts it for the environment, and checks detection is harder to read because it performs several
    _____
    .
    Hint

    The function has more than one responsibility.

    Answer

    tasks

    Explanation

    A function with many responsibilities obscures what its name means and makes its behavior harder to understand.

  47. 47
    Splitting movement-based footstep volume into its own function makes it easier to test that crouching is quieter and running is
    _____
    .
    Hint

    Compare the sound of moving slowly and carefully with moving quickly.

    Answer

    louder

    Explanation

    A movement-volume function can be checked directly with different movement types, such as expecting a higher volume for running than crouching.

  48. 48
    A separate environment function can take a volume and environment type, then return the
    _____
    .
    Hint

    It gives back the volume after accounting for the surroundings.

    Answer

    adjusted volume

    Explanation

    Separating the environmental adjustment into its own function isolates that specific task.

  49. 49
    A reusable detection function can take a volume and return a Boolean indicating whether the player is
    _____
    .
    Hint

    It answers whether guards notice the player.

    Answer

    detected

    Explanation

    Decoupling the threshold check from volume calculation lets the same detection logic be reused with different sound sources.

  50. 50
    Function names that clearly state their tasks can make code self-documenting, reducing the need for explanatory
    _____
    .
    Hint

    These are written notes in the source code.

    Answer

    comments

    Explanation

    Descriptive function names communicate what the code does, so the code may not need as many comments to explain each operation.

  51. 51
    Separating volume calculation from detection makes it easier to reuse the detection logic for a player’s
    _____
    .
    Hint

    This is another sound source that could alert guards.

    Answer

    voice

    Explanation

    A voice’s volume can be calculated separately and passed to the same independent detection function.

  52. 52
    A function should consistently return the same kind of data so that callers know what to
    _____
    .
    Hint

    Consistency makes it predictable how a result can be used.

    Answer

    expect

    Explanation

    If a function sometimes returns a number and sometimes a string, callers may encounter errors when they handle the result.

  53. 53
    In the card example, a playing card is represented as a string composed of its rank and its
    _____
    .
    Hint

    Hearts, diamonds, spades, and clubs are examples.

    Answer

    suit

    Explanation

    The card-drawing design combines a randomly chosen suit with a randomly chosen rank.

  54. 54
    A standard playing card has four possible suits: hearts, diamonds, spades, and
    _____
    .
    Hint

    It is the remaining suit in the familiar four-suit deck.

    Answer

    clubs

    Explanation

    The four suits used in the example are hearts, diamonds, spades, and clubs.

  55. 55
    A card’s rank can be ace, two through ten, jack, queen, or king, giving
    _____
    possible ranks.
    Hint

    Count ace, the numbered ranks, and the three other face cards.

    Answer

    13

    Explanation

    The example identifies thirteen ranks: ace, two through ten, jack, queen, and king.

  56. 56
    The get-rank function should convert a numeric rank to a string so that it can be combined with the other card text without a
    _____
    .
    Hint

    This error can occur when incompatible data types are combined.

    Answer

    TypeError

    Explanation

    Returning an integer for numbered ranks while returning strings for face ranks can cause a TypeError when constructing a card string.

  57. 57
    A Boolean option that controls whether face cards are allowed can make the rank-drawing function more
    _____
    .
    Hint

    The function can support different game rules through an input choice.

    Answer

    generalizable

    Explanation

    A Boolean parameter allows callers to choose whether the generated rank may include face cards.

  58. 58
    When face cards are disabled, choosing a random number from two through ten excludes ranks one, eleven, twelve, and
    _____
    .
    Hint

    This is the numeric value assigned to king in the example.

    Answer

    13

    Explanation

    The restricted range from two through ten leaves out ace, jack, queen, and king, represented by one and eleven through thirteen.

  59. 59
    If a function needs a caller’s choice about whether face cards are enabled, the caller’s choice should be passed through as a function
    _____
    .
    Hint

    The function receives this named input when it is called.

    Answer

    parameter

    Explanation

    A parameter lets the caller supply the option, and the value can then be passed on to another function that needs it.

  60. 60
    A deck model that selects cards independently without tracking previously drawn cards is not
    _____
    .
    Hint

    It does not remember which cards have already been drawn.

    Answer

    stateful

    Explanation

    Because the example does not maintain deck state, it can produce duplicate cards even when a single physical deck would not.

  61. 61
    Allowing duplicate cards can be suitable for games that use multiple decks, but it can be a bug when rules require exactly
    _____
    .
    Hint

    This is the condition expected of a single standard deck.

    Answer

    one of each card

    Explanation

    Whether duplicates are acceptable depends on the game’s requirements and use case.

  62. 62
    A Python module is created by putting code in a new file with the
    _____
    .
    Hint

    This file ending tells Python that the file contains Python code.

    Answer

    .py extension

    Explanation

    A module is a Python file, conventionally identified by its .py file extension.

  63. 63
    The file that serves as the program’s starting point is called the entry point or
    _____
    .
    Hint

    It is the one file selected to begin program execution.

    Answer

    main logic

    Explanation

    Although program code can span many modules, execution begins from a single entry-point file, conventionally named main.py.

  64. 64
    An import statement makes a module available to the program; calling one of its functions typically uses the
    _____
    before the function name.
    Hint

    It identifies which file’s namespace contains the function.

    Answer

    module name

    Explanation

    A module-qualified call uses the module name to access a function defined in that module.

  65. 65
    Importing a module is similar to copying its contents into the importing program, but module names remain separated by
    _____
    .
    Hint

    This boundary keeps names defined in different files distinct.

    Answer

    scope

    Explanation

    Module scope places names under their module’s namespace, preventing unrelated files’ names from automatically colliding.

  66. 66
    In Nim, players remove one or two stones on each turn, and the player who removes the last stone
    _____
    .
    Hint

    The goal is to avoid taking the final stone.

    Answer

    loses

    Explanation

    The Nim rules described make taking the final stone a losing move.

  67. 67
    In the Nim program, a loop continues while the number of stones in the pile is
    _____
    .
    Hint

    The game continues as long as stones remain.

    Answer

    greater than zero

    Explanation

    The while-loop condition checks whether the pile still contains stones before another turn is played.

  68. 68
    A Boolean variable can track whose turn it is because the game has
    _____
    possible player states.
    Hint

    The states correspond to the user and the computer.

    Answer

    two

    Explanation

    A Boolean can represent the user’s turn as true and the computer’s turn as false, or vice versa.

  69. 69
    The turn indicator should switch to the other player after each turn so the program can
    _____
    .
    Hint

    The user and computer take turns rather than acting consecutively.

    Answer

    alternate players

    Explanation

    Changing the Boolean turn value at the loop’s end transfers play to the other player.

  70. 70
    The computer should not take a turn after the user removes the last stone because the game is already
    _____
    .
    Hint

    No further move should occur once the pile is empty.

    Answer

    over

    Explanation

    The program alternates turns, but the computer must not move after the user ends the game by taking the last stone.

  71. 71
    To make the Nim pile less predictable, the program can choose its initial size
    _____
    .
    Hint

    The pile size should vary between games rather than always start the same way.

    Answer

    randomly

    Explanation

    Randomizing the initial number of stones makes repeated games less predictable.

  72. 72
    If the computer faces one stone, it must pick one; if it faces two stones, its best move is also to pick
    _____
    .
    Hint

    This leaves the opponent with the final stone in the two-stone case.

    Answer

    one

    Explanation

    With two stones remaining, taking one leaves one for the opponent, who then loses by taking it.

  73. 73
    With three stones remaining, the computer should take two to leave the opponent with
    _____
    .
    Hint

    The opponent is then forced to take the final stone.

    Answer

    one stone

    Explanation

    Taking two from a pile of three leaves one, which the opponent must take and lose on.

  74. 74
    With four stones remaining, taking either one or two lets the opponent respond so that the current player is left with the final
    _____
    .
    Hint

    Both possible first moves can give the opponent a way to leave one behind.

    Answer

    stone

    Explanation

    If a player takes one, the opponent can take two; if the player takes two, the opponent can take one. In either case, the first player is left to take the last stone.

  75. 75
    The Nim analysis treats leaving the opponent with four stones as a winning position because the opponent can be forced to take the
    _____
    .
    Hint

    This is the losing move under the game’s rules.

    Answer

    last stone

    Explanation

    From a pile of four, every permitted move gives the other player a response that can leave the first player with the final stone.

  76. 76
    In the example’s partial computer strategy, piles of one, two, or five stones lead the computer to pick
    _____
    .
    Hint

    These are the cases assigned the smaller of the two legal moves.

    Answer

    one stone

    Explanation

    The described algorithm selects one stone when the remaining pile size is one, two, or five.

  77. 77
    In the example’s partial computer strategy, piles of three or six stones lead the computer to pick
    _____
    .
    Hint

    These are the cases assigned the larger of the two legal moves.

    Answer

    two stones

    Explanation

    The described algorithm selects two stones when the remaining pile size is three or six.

  78. 78
    The best move for the computer when the pile has eight or nine stones is posed as an exercise, and the broader strategy can be found by looking for a
    _____
    .
    Hint

    Map out more pile sizes to identify repeating structure.

    Answer

    pattern

    Explanation

    The example suggests analyzing additional positions to discover a pattern that can improve the computer’s algorithm.

  79. 79
    A unit test checks a single unit of functionality at a time, which in most cases is a
    _____
    .
    Hint

    It is a named block of code that performs a particular task.

    Answer

    function

    Explanation

    Unit testing focuses on small units of behavior, most often individual functions.

  80. 80
    A unit test encodes a function’s requirements by calling it with inputs and checking its
    _____
    .
    Hint

    The test compares the actual output with the expected output.

    Answer

    return value

    Explanation

    A test passes when the function’s actual result matches the result required by the test.

  81. 81
    If a function’s result differs from what its test expects, the test
    _____
    .
    Hint

    This is the opposite of passing.

    Answer

    fails

    Explanation

    A test fails when the actual behavior does not satisfy the expected result or assertion.

  82. 82
    Automated unit tests can run whenever code changes and block submission until related tests
    _____
    .
    Hint

    The team requires the checks to succeed before accepting the change.

    Answer

    pass

    Explanation

    Running tests during development can enforce requirements and prevent changes that break existing behavior from being submitted.

  83. 83
    A unit test suite can act as a living contract for a function’s
    _____
    .
    Hint

    These specify the behavior the function is expected to have.

    Answer

    requirements

    Explanation

    Tests document expected behavior in executable form and can be updated when requirements intentionally change.

  84. 84
    A single test case provides weak evidence about a function because a function that always returns one fixed value could still pass it; a stronger strategy aims for code
    _____
    .
    Hint

    It measures whether the tests exercise the program’s possible execution paths.

    Answer

    coverage

    Explanation

    A test suite should cover meaningful behaviors and branches rather than relying on a single example input.

  85. 85
    A goal of code coverage is to make test cases execute every possible path of
    _____
    through a function.
    Hint

    This is the route the computer takes through the function’s branches and instructions.

    Answer

    execution

    Explanation

    Testing representative inputs for each branch helps exercise the function’s different execution paths.

  86. 86
    For a function with conditional branches based on train counts, test cases should represent each distinct class of
    _____
    .
    Hint

    These are grouped according to which branch they trigger.

    Answer

    inputs

    Explanation

    Representative input classes, such as each range of train counts, help cover the function’s conditional branches.

  87. 87
    When a bug is discovered, adding a test for that exact failure case helps ensure the same bug does not happen
    _____
    .
    Hint

    The new test guards against a repeat of the problem.

    Answer

    twice

    Explanation

    A regression test records the failure case so later changes can be checked against it.

  88. 88
    Python programmers commonly use the unit test module or the
    _____
    module for unit testing.
    Hint

    It is another popular Python testing framework named in the lesson.

    Answer

    py test

    Explanation

    The lesson identifies the unit test and py test modules as common Python testing choices.

  89. 89
    When reading a stack trace, the bottom often identifies the actual error and the line where it occurred; the rest describes the path of
    _____
    .
    Hint

    It traces how the program reached the failing line.

    Answer

    execution

    Explanation

    The lower portion of the trace provides the immediate error details, while the other entries show the sequence of calls that led there.

  90. 90
    For an independent learner, manually calling a function with several different arguments can be useful even without writing automated
    _____
    .
    Hint

    These are formal, repeatable checks written in a testing framework.

    Answer

    unit tests

    Explanation

    Trying multiple inputs helps verify expected behavior and build confidence even when a learner does not automate tests.

  91. 91
    Testing functions individually while building a program makes later debugging easier because correctly tested functions can be ruled out as the cause of a
    _____
    .
    Hint

    This is an error in the program’s behavior.

    Answer

    bug

    Explanation

    Confidence in smaller tested units narrows the search when an error appears elsewhere in the larger program.

  92. 92
    In the racing-game example, the display function takes car positions and track length, then returns a string drawing of the track
    _____
    .
    Hint

    It shows where the cars are relative to the track.

    Answer

    state

    Explanation

    The display function represents the current positions of the cars as a textual view of the track.

  93. 93
    Testing the display function in isolation revealed that a car could disappear when its position was beyond the track’s
    _____
    .
    Hint

    The original drawing loop stopped at the end of the track.

    Answer

    length

    Explanation

    The function’s loop initially drew only through the track endpoint, so it could omit a car positioned farther ahead.

  94. 94
    To display a car beyond the track endpoint, the drawing loop should continue to the greatest of the track length and both car
    _____
    .
    Hint

    The furthest car determines how far the drawing must extend.

    Answer

    positions

    Explanation

    Taking the maximum of the track length and the two car positions ensures the displayed segments reach the furthest relevant point.

  95. 95
    When both cars occupy the same track space, a display function can show a special symbol such as
    _____
    .
    Hint

    The example uses this mark to represent both cars together.

    Answer

    X

    Explanation

    A distinct symbol makes it possible to show that both cars share a position instead of displaying only one car’s symbol.

  96. 96
    To draw the shared-position symbol only in the correct segment, the display logic must check that the current position matches both car
    _____
    .
    Hint

    It is not enough for the cars to match each other; the segment being drawn must match too.

    Answer

    positions

    Explanation

    The symbol should appear only when the segment position equals the position of both cars.

  97. 97
    Breaking a suspected problem down to the individual function level makes it easier to test and debug that single
    _____
    .
    Hint

    This is the small piece of functionality under investigation.

    Answer

    unit

    Explanation

    Isolating a function narrows the problem and lets the programmer focus on one piece of behavior at a time.

1 of 97
Question 1 of 97

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent