liveBook · Manning

Turn_over

As explained in Learn AI-Assisted Python Programming, Second Edition

turn_over is a book-specific Python function that determines whether a player's turn ends based on the rolls made or the number of dice rolled.

turn_over is a small Python function that decides whether a player's dice turn has ended. It accepts the latest list of rolls and returns True when the list contains a 1 or has exactly five rolls; otherwise, it returns False. section 10.4.2 section 10.4.3

Read the function as an input-process-output task:

  • Input: rolls, a list containing the player's most recent dice rolls. section 10.4.3
  • Process: check whether 1 appears in the list or whether its length equals five. section 10.4.3
  • Output: return True when either condition ends the turn, and False otherwise. section 10.4.2

A compact implementation

def turn_over(rolls): return 1 in rolls or len(rolls) == 5 For [2, 4, 6], the result is False. For [2, 1, 6], it is True because a 1 was rolled. For five rolls without a 1, it is also True: reaching five dice ends the turn regardless of the values. section 10.4.3

Figure 10.6 Top-down design for the Bogart game
figure

Use the top-down design figure to see turn_over as one subtask inside the larger full-turn game process. section 10.4.2

How Learn AI-Assisted Python Programming, Second Edition covers it

How deep it goes
Defines and implements two checks in one Boolean expression, without descending into lower-level function internals.
Examples
Uses dice-roll lists, the turn_over function, and a full-turn game function as concrete examples.
What you can do after
Apply it via Python to recognize when a dice-based player's turn should stop.
How it connects
Connects functions, lists, Boolean values, dice rolls, and top-down design.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn AI-Assisted Python Programming, Second Edition. The section links point to the parts of the book it draws on.