Question

python. Write the function poker_hand that takes a list of exactly five distinct Card objects as an argument, analyzes the list, animport random class Card: suits = {C: \u2663, D: \u2666, H: \u2665, S: \u2660} def _init_(self, rank, suit):

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

Program:

1 import random from collections import defaultdict 2 3 4 5 class Card: suits = 6 {c: \u2663, D: \u2666, H: \u2665

27 28 def generate_deck(): deck = [Card(r, s) for r in A23456789TJQK for s in CDSH] random.shuffle(deck) return deck 29 3

51 52 # Use code Like the following to generate random 5-card hands! # hand = generate_deck[:5] 53 54 55 56 57 58 # Test case

Output:

Four of a kind
House Full
Flush
Three of a kind
One Pair
High Card

N.B. I have included two functions getSuit() and getRank() to the code.

 
Add a comment
Know the answer?
Add Answer to:
python . Write the function poker_hand that takes a list of exactly five distinct Card objects...
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
  • With the code given write python code that prints the probablity of getting a straight in...

    With the code given write python code that prints the probablity of getting a straight in poker when you run 10**5 trails. HELPER CODE: # We will represent cards as a string, e.g., 'AC' will be Ace of Clubs # Denominations: 2, ..., 10, 'J' = Jack, 'Q' = Queen, 'K' = King, 'A' = Ace Denominations = ['2','3','4','5','6','7','8','9','10','J','Q','K','A'] # Suits 'S' = Spades, 'H' = Hearts, 'D' = Diamonds, 'C' = Clubs Suits = ['C', 'H', 'S', 'D'] #...

  • A standard poker deck of 52 cards has four suits, (symbols C, H, S, and D) and thirteen ranks (sy...

    A standard poker deck of 52 cards has four suits, (symbols C, H, S, and D) and thirteen ranks (symbols A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, and K). Every card in the deck has both a value and a suit.1 A poker hand is any set of 5 cards from the standard poker deck. There are some special hands in poker, and these have ranks (i.e. some are better, some are worse). From best...

  • 1. In a standard five-card draw poker, each player receives 5 cards from a standard deck...

    1. In a standard five-card draw poker, each player receives 5 cards from a standard deck of 52 cards. Some possible hands in this game are su d in Table 1 below1 (a) Create a sample space to describe all possible hands Bill can play with Let E be the event that the hand contains at least two cards of the same rank and F be the event that the hand contains at least three cards of the same rank...

  • 1. Find the probabilities of Poker hands not covered in class. Recall in a Poker game,...

    1. Find the probabilities of Poker hands not covered in class. Recall in a Poker game, 5 cards are drawn uniformly at random from a deck of 52 cards. Each deck has 13 denominations ({A, 2, 3, . . . , 10, J Q, K)) and 4 suits (4,◇,0,6 ). In what follows consecutive denominations are But (J,Q,K, A, 21 is not considered consecutive. Find the probabilities of a. Straight Flush (5 cards of consecutive denomination, all of the same...

  • 7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing function deals a five-card...

    7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a) Determine whether the hand contains a pair. b) Determinewhetherthehandcontainstwopairs. c) Determine whether the hand contains three of a kind (e.g., three jacks). d) Determinewhetherthehandcontainsfourofakind(e.g.,fouraces). e) Determine whether the hand contains a flush (i.e., all five cards of the same suit). f) Determine whether the hand contains a straight (i.e., five cards of...

  • (Card Shuffling and Dealing) Modify the program below so that the card-dealing function deals a five-card...

    (Card Shuffling and Dealing) Modify the program below so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a) Determine whether the hand contains two pairs b) Determine whether the hand contains a full house (i.e., three of a kind with pair). c) Determinewhetherthehandcontainsastraight flush (i.e.,fivecardsofconsecutivefacevalues). d) Determine whether the hand contains a flush (i.e., five of the same suit) #include <stdio.h> #include <stdlib.h> #include <time.h> #define SUITS 4 #define FACES 13 #define CARDS...

  • Poker is a card game where you are dealt a 5 card hand from a standard...

    Poker is a card game where you are dealt a 5 card hand from a standard deck of 52 cards. This deck has 4 suits and 13 cards per suit. The rarer your hand, the higher its worth. (a) What is the probability of getting a “Full House”? A Full House is a hand where 3 cards share the same number or face, and the other 2 cards also share a different number or face. (b) What is the probability...

  • Write a Java program that deals a five-card poker hand and then determines which of the...

    Write a Java program that deals a five-card poker hand and then determines which of the following hands are contained in it: high card, pairs, two pair, three of a kind, flush. Test only for those hands. Use the numbers from 0 to 51 to represent the cards of the poker deck. 1. To deal the cards, your main method should call a secondary method that selects a random card. The secondary method should accept 5 integers that represent the...

  • Python Programming: An individual playing card is represented as a string of two characters: • the...

    Python Programming: An individual playing card is represented as a string of two characters: • the first character is from "23456789TJQKA" and represents the rank, i.e., the number or value of the card. (Note that 10 is encoded as letter T to make all card ranks to be single letters) • the second character is from "cdhs" and represents the suit (clubs, diamonds, hearts and spades respectively). For example, "Jd" would be the jack of diamonds, and "4s" would be...

  • Create A Header file and A CPP File for this we want to simulate drawing cards...

    Create A Header file and A CPP File for this we want to simulate drawing cards from a deck,with or without replacement. With replacement means that the card is placed back in the deck after having been drawn. You will want to design a class that represents a deck of card (52 cards. 13 cards: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King) The class is to be called “aDeckOfCards”. And it should generate a...

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
ADVERTISEMENT