Question

In the Python code below, use the array built to shuffle and deal TWO cards for...

In the Python code below, use the array built to shuffle and deal TWO cards for THREE  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 THREE hands.  

  1. Deal two cards for three hands
  2. Computer the total card value per hand.
  3. Add a function that will determine whether the amount of the hand is Less than 17,
  4. if so add a card and perform #3 again and until the hand >= 17
  5. Perform this for each hand
  6. the program is finished when each hand is > 17.
  7. Provide the code and flow chart for this program.

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

Homework Answers

Answer #1

dCardNames = ['2','3','4','5','6','7','8','9','10','J','Q','K','A']
dCardValues = ['2','3','4','5','6','7','8','9','10','11','12','13','14']
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

from random import randint
# To shuffle 52 cards
i=51
while i>0:
newindex=randint(0,i)
name=aCards[0][i]
value=aCards[1][i]
suit=aCards[2][i]
aCards[0][i]=aCards[0][newindex]
aCards[1][i]=aCards[1][newindex]
aCards[2][i]=aCards[2][newindex]
aCards[0][newindex]=name
aCards[1][newindex]=value
aCards[2][newindex]=suit
i=i-1
i=0
# Shuffled list
print('After shuffling:')
while i < 52:
print (aCards[0][i], " ", aCards[1][i], " ", aCards[2][i])
i = i + 1
# Hand 1: Top two cards of shuffles deck
print('Hand 1:')
print (aCards[0][51], " ", aCards[1][51], " ", aCards[2][51])
print (aCards[0][50], " ", aCards[1][50], " ", aCards[2][50])

# Hand 2:
print('Hand 2:')
print (aCards[0][49], " ", aCards[1][49], " ", aCards[2][49])
print (aCards[0][51], " ", aCards[1][48], " ", aCards[2][48])


Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
8) You shuffle a deck of two red cards and two blue cards. Then you deal...
8) You shuffle a deck of two red cards and two blue cards. Then you deal the four cards face down. You then turn two cards face up. 1) Draw a decision tree to identify the choices. 2) What is the probability that both cards facing up are red? 9) Create a decision diagram for a major decision in your life. The decision must have at least 3 issues. For instance you are deciding to take an umbrella with you...
A deck of cards has 52 cards with 4 suits (Hearts, Diamonds, Spades, and Clubs) and...
A deck of cards has 52 cards with 4 suits (Hearts, Diamonds, Spades, and Clubs) and 13 cards in each suit (Ace thru 10, Jack, Queen, and King; the last three are considered face cards). A card is drawn at random from a standard 52-card deck.   What is the probability that the card is a number card given the card is black (Spades and Clubs)? Group of answer choices 6/26 1 - 10/26 20/52 10/13
Probabilities with a deck of cards. There are 52 cards in a standard deck of cards....
Probabilities with a deck of cards. There are 52 cards in a standard deck of cards. There are 4 suits (Clubs, Hearts, Diamonds, and Spades) and there are 13 cards in each suit. Clubs/Spades are black, Hearts/Diamonds are red. There are 12 face cards. Face cards are those with a Jack (J), King (K), or Queen (Q) on them. For this question, we will consider the Ace (A) card to be a number card (i.e., number 1). Then for each...
Q19. Consider an ordinary 52-card North American playing deck (4 suits, 13 cards in each suit)....
Q19. Consider an ordinary 52-card North American playing deck (4 suits, 13 cards in each suit). a) How many different 5−card poker hands can be drawn from the deck? b) How many different 13−card bridge hands can be drawn from the deck? c) What is the probability of an all-spade 5−card poker hand? d) What is the probability of a flush (5−cards from the same suit)? e) What is the probability that a 5−card poker hand contains exactly 3 Kings...
With the code given write python code that prints the probability of getting a flush when...
With the code given write python code that prints the probability of getting a flush when you run 10**5 trails. this is what i have so far but it says that isFlush is not defined. why? # Print out probability that a 5-card hand has all the same suit #seed(0) num_trials = 10**5 trials = [dealHand for k in range(num_trials)] # 5 card hand prob = sum([l for h in trials if isFlush(h)])/num_trials # sum the list of numbers that...
a) Describe an experiments of the drawing of three cards from a deck of cards from...
a) Describe an experiments of the drawing of three cards from a deck of cards from which the jacks, queens and kings have been removed. (Note: these are 52 cards in a deck--13 cards are hearts, 13 cards are diamonds., 13 cards are clubs, and 13 cards are spades. A card with an ace counts as 1. Nine cards of each suit are marked 2 through 10. Ignore the jacks, queens, and kings, leaving 40 cards from which to draw.)...
A deck of playing cards has 52 = 4 × 13 cards: there are 4 suits...
A deck of playing cards has 52 = 4 × 13 cards: there are 4 suits (two red and two black) and 13 cards in each suit. How many 3-card hands of the following types are there? (1) All 3 of the same suit? ( 2) All 3 cards of different suits? (3) All 3 cards of different value ?
A standard French deck of playing cards has 52 cards, of which, 13are clubs, 13 are...
A standard French deck of playing cards has 52 cards, of which, 13are clubs, 13 are diamonds, 13 are hearts, and 13 are spades. A poker hand consists of 5 cards drawn from a standard deck. A bridge handconsists of 13 cards drawn from a standard deck. (a) How many poker hands will contain 2 clubs, 1 diamond, and 2hearts? (b) How many bridge hands will contain 6 diamonds and 7 spades? (c) How many bridge hands will contain 5...
As shown above, a classic deck of cards is made up of 52 cards, 26 are...
As shown above, a classic deck of cards is made up of 52 cards, 26 are black, 26 are red. Each color is split into two suits of 13 cards each (clubs and spades are black and hearts and diamonds are red). Each suit is split into 13 individual cards (Ace, 2-10, Jack, Queen, and King). If you select a card at random, what is the probability of getting: 1) A(n) 8 of Heart s? 2) A Club or Spade?...
You have a shuffled deck of n=15 cards: 0,…,14. You deal out the 15 cards. Let...
You have a shuffled deck of n=15 cards: 0,…,14. You deal out the 15 cards. Let Eidenote the event that the ith card dealt was even, and let Oi denote the event that the ith card dealt was odd. (a) What is P[E2|E1], the probability that the second card is even given that the first card is even? (b) What is P[E2|O1], the probability that the second card is even given that the first card is odd? (c) What is...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT