Question: I have an assignment to finish the code for a poker game in Pthon 3.6. I am tasked with checking the 5 cards drawn to

I have an assignment to finish the code for a poker game in Pthon 3.6. I am tasked with checking the 5 cards drawn to see what poker hand they got. The royal flush and straight flush are already finished. I have to check for a full house, four of a kind, straight, flush, three of a kind, two pairs, and a pair. A lot of this code is already finished. I just have to write the code to check for the above hands. I would also like it to be formatted how the first two are formatted. Any help would be great.

This is the code I currently have.

import random def dealHand(): # we are playing with Aces high in this game # so an Ace is 14, not 2 # build deck as a list deck = [] for value in range(2,15): for suit in range(1,5): if suit == 1: # D for diamonds if value < 10: card = "D" + "0"+ str(value) else: card = "D" + str(value) elif suit == 2: # C for clubs if value < 10: card = "C" + "0"+ str(value) else: card = "C" + str(value) elif suit == 3: # S for spades if value < 10: card = "S" + "0"+ str(value) else: card = "S" + str(value) else: # H for hearts if value < 10: card = "H" + "0"+ str(value) else: card = "H" + str(value) deck.append(card) # build hand to return deal = deck.copy() hand = [] for d in range(5): index = random.randrange(52) while(deal[index] == ""): index = random.randrange(52) hand.append(deal[index]) #take card out of deck so it can't be used again deal[index] = "" # return hand to be used by the caller return hand def isRoyalFlush(list): # check for all the same suit in the hand # pull out first card in list to compare rest to card1 = list[0] suit1 = card1[0] # use loop to see if all are the same suit for card in list: if card[0] != suit1: return False # check for values of Ace, King, Queen, Jack, Ten in hand values = [10, 11, 12, 13, 14] for card in list: cardvalue = int(card[1]+card[2]) if(cardvalue not in values): return False # if make it past the above checks, then it must be a Royal Flush return True

def isStraightFlush(list): # check for same suit card1 = list[0] suit1 = card1[0] for card in list: if card[0] != suit1: return False # check for 5 cards in a sequence # make a list of card values values = [] for card in list: cardvalue = int(card[1]+card[2]) values.append(cardvalue) values.sort() print(values) for index, value in enumerate(values): if index == (len(values)-1): break if (value+1) != (values[(index+1)]): return False # Otherwise, it's a straight flush return True

def isFourKind(list): return True

def isFullHouse(list): return True

def isFlush(list): return True

def isStraight(list): return True

def isThreeKind(list): return True

def isTwoPair(list): return True

def isPair(list): return True

# Fill in the rest of the functions here # Make sure you use the names referenced by main for each function

def main(): print("This program will tell you which poker hand you were dealt") print("You will be dealt 5 cards.") print("Good luck!") # get hand and print it hand = dealHand() print("Your hand is: ") print(hand) # to test each new function you write, use a non-random hand # by uncommenting and changing the lines below # hand = ["D02", "D05", "D04", "D06", "D08"] # print(hand) # remember to comment out this line again once you finish testing # check to see which type of hand you have been dealt if(isRoyalFlush(hand)): #check for a Royal Flush print("You have a Royal Flush.") elif(isStraightFlush(hand)): #check for a Straight Flush print("You have a Straight Flush.") elif(isFourKind(hand)): # check for 4 of a kind print("You have a Four of a Kind.") elif(isFullHouse(hand)): # check for Full House print("You have a Full House.") elif(isFlush(hand)): # check for flush print("You have a Flush.") elif(isStraight(hand)): # check for straight print("You have a Straight.") elif(isThreeKind(hand)): # check for three of a kind print("You have a Three of a Kind.") elif(isTwoPair(hand)): # check for two pair print("You have Two Pair.") elif(isPair(hand)): # check for a pair print("You have a Pair.") else: # finally return High Card if nothing else print("Sorry, you must use your high card to play.") main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!