all information are in the files uploaded.
Background Information
• A three-card poker hand consists of any three cards from a standard 52-card deck. For a single card, there are 13 possible ranks (two, three, four, five, six, seven, eight, nine, ten, jack, queen,
king, ace) and 4 possible suits (clubs, diamonds, hearts, spades).
A Flush occurs when all cards have the same suit.
• Three of a kind occurs when all cards have the same rank.
• Two of a kind occurs when two of the three cards have the same rank.
• If none of the above three situations applies, the hand is worth Nothing.
Assignment
• Download poker.py and modify it so that when it is run on this input file, it produces this output file.
Assumptions
• The input file contains an unknown number of poker hands. Each line contains a three card poker hand in this format: Card 1 Rank, Card 1 Suit, Card 2 Rank, Card 2 Suit, Card 3 Rank,
Card 3 Suit.
• All poker hands are valid and use only lowercase letters.
Grading – 100 points
• 10 points – Every Flush is identified correctly.
• 10 points – Every Three of a Kind is identified correctly.
• 10 points – Every Two of a Kind is identified correctly.
• 10 points – Every Nothing is identified correctly.
• 10 points – At least three of the following boolean functions exist and are used correctly in the solution: flush, three_of_a_kind, two_of_a_kind and nothing.
• 15 points – The format of the output file matches the format of the sample output file above exactly. (3 points for each type of difference up to 15 points.)
• 15 points – The Python solution is properly commented, easy to understand and does not contain unnecessary code. (3 points for each type of improvement up to 15 points.)
• 20 points – All output appears in the correct output file (15 points) and no output appears in the Python shell (5 points).
#
Do not change anything below this line
def main(poker_input, poker_output, cards_in_hand):
for hand in poker_input:
hand – hand.split()
hand_as_list = []
for i in range (cards_in_hand):
hand_as_list.append( [hand[0], hand[1]])
hand – hand[2:]
print_hand (hand_as_list, poker_output)
evaluate (hand_as_list, poker_output)
poker_input open(“poker.in”, “r”)
poker_output open(“poker.out”, “w”)
main(poker_input, poker_output, 3)
poker_input.close()
poker_output.close()
ace hearts king hearts queen hearts
three diamonds three spades three clubs
two hearts two diamonds four hearts
five hearts six diamonds five clubs
seven hearts eight diamonds eight hearts
ten hearts nine diamonds jack hearts
Poker Hand
Card 1: Ace of Hearts
Card 2: King of Hearts
Card 3: Queen of Hearts
Poker Hand Evaluation: FLUSH
Poker Hand
Card 1: Three of Diamonds
Card 2: Three of Spades
Card 3: Three of clubs
Poker Hand Evaluation: THREE OF A KIND
Poker Hand
Card 1: Two of Hearts
Card 2: Two of Diamonds
Card 3: Four of Hearts
Poker Hand Evaluation: TWO OF A KIND
Poker Hand
Card 1: Five of Hearts
Card 2: Six of Diamonds
Card 3: Five of Clubs
Poker Hand Evaluation: TWO OF A KIND
Poker Hand
Card 1: Seven of Hearts
Card 2: Eight of Diamonds
Card 3: Eight of Hearts
Poker Hand Evaluation: TWO OF A KIND
Poker Hand
Card 1: Ten of Hearts
Card 2: Nine of Diamonds
Card 3: Jack of Hearts
Poker Hand Evaluation: NOTHING