Question

Programming Langaue(Python 3) Define a function deal that will shuffle and distribute the 52 playing cards...

Programming Langaue(Python 3)

Define a function deal that will shuffle and distribute the 52 playing cards evenly to two players (26 each) and return a tuple of each player's hand (as a list of values). The function does not need to take in any arguments, and should create the deck of values internally (i.e., you should not need to input the deck of values into the function; you may reuse the statement you developed for part 6.1). You may assume that you are always playing with a standard deck (52 cards). You may make use of any NumPy functionality to perform the shuffle operation. Validate the operation of your function by dealing a hand to two players and displaying each player's hand along with their number of cards and the associated total value.
  
Testing code:
p1, p2 = deal() print('Player 1s hand:', p1, len(p1), sum(p1)) print('Player 2s hand:', p2, len(p2), sum(p2))

Player 1s hand: [1, 13, 6, 5, 4, 8, 11, 10, 1, 7, 2, 12, 10, 3, 12, 3, 9, 4, 9, 10, 5, 3, 9, 1, 7, 13] 26 178 Player 2s hand: [8, 5, 7, 13, 8, 6, 13, 5, 3, 2, 4, 4, 2, 6, 2, 1, 11, 6, 8, 12, 12, 7, 11, 11, 10, 9] 26 186
  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any questions let me know in below comments.

Here is the code:

import numpy as np
def deal():
deck_arry = np.array([list(range(1,14)),list(range(1,14)),list(range(1,14)),list(range(1,14))])
deck_arry = deck_arry.ravel()
np.random.shuffle(deck_arry)
player1 = tuple(deck_arry[:int(len(deck_arry)/2)])
player2 = tuple(deck_arry[int(len(deck_arry)/2):])
return list(player1),list(player2)
p1, p2 = deal()
print('Player 1s hand:', p1, len(p1), sum(p1))
print('Player 2s hand:', p2, len(p2), sum(p2))

Output:

[5]: import numpy as np def deal(): deck_arry = np.array([list(range(1,14)), list(range (1,14)), list(range(1,14)), list (ran
  

Add a comment
Know the answer?
Add Answer to:
Programming Langaue(Python 3) Define a function deal that will shuffle and distribute the 52 playing cards...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Part 1: Experimental Probabilities. 1. Using a standard deck of 52 playing cards, shuffle the deck...

    Part 1: Experimental Probabilities. 1. Using a standard deck of 52 playing cards, shuffle the deck well, then draw 10 cards. Record the number of diamonds. If you do not have a deck of playing cards go to random.org, under the games and lotteries link, choose playing card shuffler. Repeat this 27 more times (for a total of 28 trials) and record your data below. (10 pts) Draw # of Diamonds 1 2 3 4 5 6 7 8 9...

  • C++ Purpose: To practice arrays of records, and stepwise program development. 1. Define a record data...

    C++ Purpose: To practice arrays of records, and stepwise program development. 1. Define a record data type for a single playing card. A playing card has a suit ('H','D','S',or 'C'), and a value (1 through 13). Your record data type should have two fields: a suit field of type char, and a value field of type int. 2. In main(), declare an array with space for 52 records, representing a deck of playing cards. 3. Define a function called initialize()...

  • How many ways are there to deal 52 standard playing cards to four players (so that...

    How many ways are there to deal 52 standard playing cards to four players (so that each player gets 13 cards)? Suppose you are world champion in card dealing, and can deal 52 cards in just one second. Compare the time it would need you to deal all possible combinations with the current age of the universe. (If there are x ways of dealing the cards, then it takes x seconds for you to deal the cards. Now compare the...

  • 6. How many ways are there to deal 52 standard playing cards to four players (so...

    6. How many ways are there to deal 52 standard playing cards to four players (so that cach player g: 13 cardi)? Supp you are workl chapion in card daling and can deal 52 cards in just one second. Compare the time it would need you to deal all possible combinations with the current age of the universe.

  • The question is to make the game of war using Python. The information on how the...

    The question is to make the game of war using Python. The information on how the cards will be represented and how the game will be played along with 2 sample runs is below. Representation of the deck of cards: The deck of cards will be simulated with integers of values from 1 to 13, where 1 represents the Ace, 11 the Jack, 12 the Queen, and 13 the King – these integers also represent the face values of the...

  • C Programming The following code creates a deck of cards, shuffles it, and deals to players....

    C Programming The following code creates a deck of cards, shuffles it, and deals to players. This program receives command line input [1-13] for number of players and command line input [1-13] for number of cards. Please modify this code to deal cards in a poker game. Command line input must accept [2-10] players and [5] cards only per player. Please validate input. Then, display the sorted hands, and then display the sorted hands - labeling each hand with its...

  • 7. There are 52 playing cards; let S be the set of all of them. A "deck" is a particular order (o...

    7. There are 52 playing cards; let S be the set of all of them. A "deck" is a particular order (or permutation) of the 52 cards. Mathematically, a deck can be represented by (ci,, 2) where ci,c2,., cs2 are all the elements of S. The interpretation is that ci is the first card in the deck, c2 is the second card, and so on. Let 2 be the set of all possible decks. a) Is Ω a subset of...

  • 13. [3] You shuffle a deck of playing cards and the chance you get a diamond...

    13. [3] You shuffle a deck of playing cards and the chance you get a diamond card is 0.25. You repeat this process 200 times, putting the card back each time, and out of those 200 attempts you get 57 diamond cards. This demonstrates a. The law of large numbers b. The law of averages 14. [3] You shuffle a deck of playing cards and the chance you get a diamond card is 0.25. You repeat this process times, putting...

  • War—A Card game Playing cards are used in many computer games, including versions of such classic...

    War—A Card game Playing cards are used in many computer games, including versions of such classics as solitaire, hearts, and poker. War:    Deal two Cards—one for the computer and one for the player—and determine the higher card, then display a message indicating whether the cards are equal, the computer won, or the player won. (Playing cards are considered equal when they have the same value, no matter what their suit is.) For this game, assume the Ace (value 1) is...

  • The following question involves a standard deck of 52 playing cards. In such a deck of...

    The following question involves a standard deck of 52 playing cards. In such a deck of cards there are four suits of 13 cards each. The four suits are: hearts, diamonds, clubs, and spades. The 26 cards included in hearts and diamonds are red. The 26 cards included in clubs and spades are black. The 13 cards in each suit are: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, and Ace. This means there are four...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT