In the attached Python code, use the array built to shuffle and deal two poker hands. Change the corresponding values for all Jacks through Aces to 11, 12, 13, 14 respectively. Shuffle the deck using your written shuffle routine, then deal two hands. COMMENT (explain) YOUR CODE Code: dCardNames = ['2','3','4','5','6','7','8','9','10','J','Q','K','A'] dCardValues = ['2','3','4','5','6','7','8','9','10','10','10','10','11'] dSuits = ["Clubs","Spades","Diamonds","Hearts"] # Build a two dimensional deck with Cards suits and values. aCards = [['' for i in range(52)] for j in range(3)] i = 0 n = 0 while i < 13: aCards[0][i] = dCardNames[i] aCards[0][i + 13] = dCardNames[i] aCards[0][i + 26] = dCardNames[i] aCards[0][i + 39] = dCardNames[i] aCards[1][i] = dSuits[0] aCards[1][i + 13] = dSuits[1] aCards[1][i + 26] = dSuits[2] aCards[1][i + 39] = dSuits[3] aCards[2][i] = dCardValues[i] aCards[2][i + 13] = dCardValues[i] aCards[2][i + 26] = dCardValues[i] aCards[2][i + 39] = dCardValues[i] i = i + 1 i = 0 while i < 52: print (aCards[0][i], " ", aCards[1][i], " ", aCards[2][i]) i = i + 1

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
In the attached Python code, use the array built to shuffle and deal two poker hands. Change the corresponding values for all Jacks through Aces to 11, 12, 13, 14 respectively. Shuffle the deck using your written shuffle routine, then deal two hands. COMMENT (explain) YOUR CODE Code: dCardNames = ['2','3','4','5','6','7','8','9','10','J','Q','K','A'] dCardValues = ['2','3','4','5','6','7','8','9','10','10','10','10','11'] dSuits = ["Clubs","Spades","Diamonds","Hearts"] # Build a two dimensional deck with Cards suits and values. aCards = [['' for i in range(52)] for j in range(3)] i = 0 n = 0 while i < 13: aCards[0][i] = dCardNames[i] aCards[0][i + 13] = dCardNames[i] aCards[0][i + 26] = dCardNames[i] aCards[0][i + 39] = dCardNames[i] aCards[1][i] = dSuits[0] aCards[1][i + 13] = dSuits[1] aCards[1][i + 26] = dSuits[2] aCards[1][i + 39] = dSuits[3] aCards[2][i] = dCardValues[i] aCards[2][i + 13] = dCardValues[i] aCards[2][i + 26] = dCardValues[i] aCards[2][i + 39] = dCardValues[i] i = i + 1 i = 0 while i < 52: print (aCards[0][i], " ", aCards[1][i], " ", aCards[2][i]) i = i + 1
## Python Code Explanation: Building a Deck of Cards

This Python script defines and creates a deck of cards using a 2-dimensional array. The deck includes suits and values for each card, and the code demonstrates how to organize and print them.

### Code Breakdown

- **Card Definitions:**
  - `dCardNames`: A list of card names, ranging from '2' to 'A' (Ace), including face cards 'J', 'Q', 'K'.
  - `dCardValues`: A list of corresponding card values, where face cards ('J', 'Q', 'K', 'A') have value '10' and '11' respectively.
  - `dSuits`: A list of card suits, namely "Clubs", "Spades", "Diamonds", "Hearts".

- **Deck Initialization:**
  - `aCards`: A 2-dimensional list initialized to hold 52 cards using nested list comprehension. Each entry will contain a card name, suit, and value.
  
- **Deck Construction:**
  - A `while` loop iterates over the first 13 indices to distribute card names and values across all four suits in the deck:
    - `aCards[0][i]`: Assigns card names to cards.
    - `aCards[1][i]`: Assigns suits by cycling through each suit every 13 cards.
    - `aCards[2][i]`: Assigns card values.

- **Printing the Deck:**
  - Another `while` loop iterates through all 52 cards to print each card's name, suit, and value in a formatted manner.

### Code Execution

This script, when executed, will output each card in the deck, showing its name, suit, and respective value. It effectively demonstrates how to programmatically handle and display a complete deck of cards using Python data structures.
Transcribed Image Text:## Python Code Explanation: Building a Deck of Cards This Python script defines and creates a deck of cards using a 2-dimensional array. The deck includes suits and values for each card, and the code demonstrates how to organize and print them. ### Code Breakdown - **Card Definitions:** - `dCardNames`: A list of card names, ranging from '2' to 'A' (Ace), including face cards 'J', 'Q', 'K'. - `dCardValues`: A list of corresponding card values, where face cards ('J', 'Q', 'K', 'A') have value '10' and '11' respectively. - `dSuits`: A list of card suits, namely "Clubs", "Spades", "Diamonds", "Hearts". - **Deck Initialization:** - `aCards`: A 2-dimensional list initialized to hold 52 cards using nested list comprehension. Each entry will contain a card name, suit, and value. - **Deck Construction:** - A `while` loop iterates over the first 13 indices to distribute card names and values across all four suits in the deck: - `aCards[0][i]`: Assigns card names to cards. - `aCards[1][i]`: Assigns suits by cycling through each suit every 13 cards. - `aCards[2][i]`: Assigns card values. - **Printing the Deck:** - Another `while` loop iterates through all 52 cards to print each card's name, suit, and value in a formatted manner. ### Code Execution This script, when executed, will output each card in the deck, showing its name, suit, and respective value. It effectively demonstrates how to programmatically handle and display a complete deck of cards using Python data structures.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Array
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