ello. I need help forming my hierarchy chart from my python code. Can I add comp_move to both get_computer_play() and main() functions? And should I remove import random as it's not a function?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hello. I need help forming my hierarchy chart from my python code. Can I add comp_move to both get_computer_play() and main() functions? And should I remove import random as it's not a function?

The image contains a Python script for a simple command-line game of "Rock, Paper, Scissors" against the computer. Below is the transcription and explanation of its components:

### Functions:

1. **def get_user_play(name, rock=0, paper=1, scissors=2):**
   - Prompts user to input their move (0 for Rock, 1 for Paper, 2 for Scissors).
   - Validates input and displays the move as "Rock", "Paper", or "Scissors".
   - Returns the user's move.

2. **def get_computer_play(rock=0, paper=1, scissors=2):**
   - Randomly selects a move for the computer (0 for Rock, 1 for Paper, 2 for Scissors).
   - Displays the computer's selected move.
   - Returns the computer's move.

### Main Script:

- **def main():**
  - Greets the player and asks for their name.
  - Describes the rules of the game:
    - Rock breaks Scissors
    - Scissors cuts Paper
    - Paper covers Rock
    - Same choices result in a tie
  - Initializes score counters for the player and the computer.
  - Starts an infinite game loop:
    - Gets the user's move through `get_user_play`.
    - Breaks the loop if the input is invalid.
    - Gets the computer's move through `get_computer_play`.
    - Determines the winner by comparing moves: 
        - 'Rock' vs 'Scissors' -> Rock wins
        - 'Scissors' vs 'Paper' -> Scissors wins
        - 'Paper' vs 'Rock' -> Paper wins
    - Updates and displays scores based on the results.
  - Ends by displaying the total number of games played, won by the user, won by the computer, and ties.

This script demonstrates basic control structures in Python, such as functions, conditionals, loops, and user input handling.
Transcribed Image Text:The image contains a Python script for a simple command-line game of "Rock, Paper, Scissors" against the computer. Below is the transcription and explanation of its components: ### Functions: 1. **def get_user_play(name, rock=0, paper=1, scissors=2):** - Prompts user to input their move (0 for Rock, 1 for Paper, 2 for Scissors). - Validates input and displays the move as "Rock", "Paper", or "Scissors". - Returns the user's move. 2. **def get_computer_play(rock=0, paper=1, scissors=2):** - Randomly selects a move for the computer (0 for Rock, 1 for Paper, 2 for Scissors). - Displays the computer's selected move. - Returns the computer's move. ### Main Script: - **def main():** - Greets the player and asks for their name. - Describes the rules of the game: - Rock breaks Scissors - Scissors cuts Paper - Paper covers Rock - Same choices result in a tie - Initializes score counters for the player and the computer. - Starts an infinite game loop: - Gets the user's move through `get_user_play`. - Breaks the loop if the input is invalid. - Gets the computer's move through `get_computer_play`. - Determines the winner by comparing moves: - 'Rock' vs 'Scissors' -> Rock wins - 'Scissors' vs 'Paper' -> Scissors wins - 'Paper' vs 'Rock' -> Paper wins - Updates and displays scores based on the results. - Ends by displaying the total number of games played, won by the user, won by the computer, and ties. This script demonstrates basic control structures in Python, such as functions, conditionals, loops, and user input handling.
### Hierarchy Chart: OLAG

This diagram represents the structure of a program using a hierarchy chart, detailing how functions are organized and their relationships within the program.

#### Main Components:

- **main()**: 
  - This is the top-level function from which the program execution begins.
  
#### Function Breakdown:

- **get_user_play()**:
  - This function is responsible for capturing the user's move.
  - **move()**: A subordinate function to `get_user_play()`, likely handling the details of registering or executing the move.
  
- **import random**:
  - This is not a function but indicates the program imports the `random` module, essential for generating random numbers or functionality within the program.
  
- **get_computer_play()**:
  - This function is designed to determine the computer's move.
  - **comp_num()**: A function possibly used to generate or store a computer's move in numerical form.
  
- **main()**: (second instance)
  - This may indicate a reference for further operations or another scope within the program.
  - **name1()**: Could be used for naming or identifying operations, potentially related to computer play.
  - **user_move()**: Likely functions to handle specific details about the user's move, ensuring it is processed within the program's flow.

This hierarchy chart helps in visualizing how the program is structured, making it easier to understand the call relations between different functions and modules.
Transcribed Image Text:### Hierarchy Chart: OLAG This diagram represents the structure of a program using a hierarchy chart, detailing how functions are organized and their relationships within the program. #### Main Components: - **main()**: - This is the top-level function from which the program execution begins. #### Function Breakdown: - **get_user_play()**: - This function is responsible for capturing the user's move. - **move()**: A subordinate function to `get_user_play()`, likely handling the details of registering or executing the move. - **import random**: - This is not a function but indicates the program imports the `random` module, essential for generating random numbers or functionality within the program. - **get_computer_play()**: - This function is designed to determine the computer's move. - **comp_num()**: A function possibly used to generate or store a computer's move in numerical form. - **main()**: (second instance) - This may indicate a reference for further operations or another scope within the program. - **name1()**: Could be used for naming or identifying operations, potentially related to computer play. - **user_move()**: Likely functions to handle specific details about the user's move, ensuring it is processed within the program's flow. This hierarchy chart helps in visualizing how the program is structured, making it easier to understand the call relations between different functions and modules.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Algebraic Expressions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education