Write a Python method that takes two strings of five characters. The first strin
ID: 671820 • Letter: W
Question
Write a Python method that takes two strings of five characters. The first string represents card values (ace (a), king (k), queen (q), jack (j), ten (t), or 2-9). The second string consists of the suits of the cards (diamonds (d), clubs (c), hearts (h), spades (s)). First, check that the string is a valid poker hand (it must consist of only the previous mentioned values). If it is invalid, return "invalid hand". If it is a valid hand, return what hand it is:
high card: highest card in the hand
one pair: one matching pair exists in the hand
two pair: two matching pairs exist in the hand
three of a kind: three matching cards in the hand
full house: a pair plus three of a kind
four of a kind: four of the same cards in the hand
straight: the five cards are in a sequence (ex: 34567, tjqka, or 789tj)
flush: all five cards are the same suit
royal straight flush: flush plus the cards are akqjt
Use regular expressions for validate hand, test for two of a kind, and test for 3 of a kind.
Explanation / Answer
class TestPoker:
def checkRoyalStriaght(self,string1, string2):
if "hhhhh" || "sssss" || "ddddd" || "ccccc" in string2
from itertools import permutations
perms = [''.join(p) for p in permutations(string1)]
if "akqjt" in perms
print "Its a ROyal Straight!"
def checkFlush(self,string1,string2):
if "hhhhh" || "sssss" || "ddddd" || "ccccc" in string2
print "FLUSH!"
def checkStraight(self,string1,string2):
num=(int)string1
if array in num
print "STRAIGHT"
##Here define array as 12345,23456,34567 as string of these combinations
def checkHighCard(self,string1,string2):
num=(int)string1
if array in num
if "hhhhh" || "sssss" || "ddddd" || "ccccc" in string2
print "HIGH CARD"
##Here define array as 12345,23456,34567 as string of these combinations
def checkHighCard(self,string1,string2):
num=(int)string1
p=TestPoker
print "Enter First String:",
string1 = raw_input()
print "Enter Second String:",
string2 = raw_input()
p.checkRoyalStriaght(string1,string2)
##Likewise you can check all the valid Hands
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.