Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python programming language required!!! . 2. In a standard 52-card deck, each card has a rank (2,3,4,5, 6, 7, 8, 9, 10, Jack, Queen, King,

Python programming language required!!!

image text in transcribed

. 2. In a standard 52-card deck, each card has a rank (2,3,4,5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace) and a suit (clubs, diamonds, hearts, spades). We will consider ranks to be ordered as in the list above; aces are always high. We will use these abbreviations: T = 10, J = Jack, Q = Queen, K = King, A = Ace C = clubs, D = diamonds, H = hearts, S = spades So we can represent a card using 2 characters. For example, '2' is the 2 of clubs, 'TS' is the 10 of spades, and 'KD' is the king of diamonds. In a certain game, each hand consists of 5 cards, which must all be different. Each hand is classified as one of the following. (Note that suits are ignored in classification.) four of a kind; for example, 5S 8S 5D 5H 5C is four 5's three of a kind: for example, KS 7C KD 8D KC is three Kings pair: for example, 8D 8S KC 9D TH is a pair of 8's. If there is more than one pair, the higher pair is used in the classification. For example, 8D 85 7C 7D KH is a pair of 8's, not a pair of 7's. no pair: for example, 9D AS TH 8H 5D is an Ace high. The highest-ranking card is included in the classification. Some hands are better than others. Any four of a kind beats any three of a kind, which beats any pair, which beats any no pair hand. Within each category, hands are ordered by rank. For example, four Jacks beat four 7's, and a King high beats a Queen high. If two hands have the same category including rank, then they are equal. For example, any two hands that are classified as three kings are equal (the additional cards that are not Kings are not used in comparing the hands). Similarly, any two hands that are classified as a pair of 8's are equal (any additional lower pairs are not used in comparing the hands) Write a class Hand that represents a hand of cards. It should support the following operations: Hand(s) - create a Hand from a string such as '8D 8S KC 9D TH' h.classify0 return a pair (n. r), where n is a category (4 = four of a kind, 3 = three of a kind, 2 = pair, 1 = no pair) and r is a rank (a string). For example, (3, 'K') means three Kings. h.better(h2) return True if hand h is better than hand h2, otherwise False n._repr_0) - return a string such as '8D 8S KC 9D TH' For example: >>> n = Hand('5S 8S 5D KH 5C") >>> h2 = Hand( 'KD AS 2C KH 3D') >>> h3 = Hand('QD QH JD JH 70') >>> h.classify() (3, '5'). >>> h2.classify (2, 'K) >>> h3.classify (2, 'Q') >>> h.better (h2) True >>> h2.better (3) True

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

International Financial Reporting Standards A Practical Guide

Authors: Hennie Van Greuning

4th Edition

0821367684, 978-0821367681

Students also viewed these Databases questions