liveBook · Manning

Roll_dice

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

roll_dice is a book-specific Python function that rolls a specified number of dice and returns their results as a list.

roll_dice is a small Python function for rolling a chosen number of dice. It accepts the number of dice as a parameter and returns the results as a list, such as [6, 1, 4]. In the Bogart game, it separates dice rolling from the larger task of managing a player's turn. section 10.4.2 section 10.4.3

Rolling three dice

Calling roll_dice(3) might print three values and return [6, 1, 4]. The returned list can then be passed to turn_over, which checks whether a 1 was rolled or whether five dice have been reached. section 10.4.2

Figure 10.6 Top-down design for the Bogart game
figure

Use the top-down design figure to see roll_dice as a focused subtask within the Bogart game's turn-management structure. section 10.4.2

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

How deep it goes
Explains parameters, looping, random generation, printing, list construction, and returning results without descending into randomness internals.
Examples
Uses a three-dice result such as [6, 1, 4] and the Bogart implementation with random.randint.
What you can do after
Builds a reusable Python dice-rolling function that displays and returns a chosen number of random die results.
How it connects
Connects functions, parameters, return values, lists, loops, random number generation, and turn-based game logic.

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.