Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need help with this program def get_all_ranks(hand): result = [] for card in hand: result.append(card[0]) return result def straight_flush(hand): def straight(hand): def four_of_a_kind(hand): def

i need help with this program

image text in transcribed

def get_all_ranks(hand): result = [] for card in hand: result.append(card[0]) return result

def straight_flush(hand):

def straight(hand):

def four_of_a_kind(hand):

def full_house(hand):

def flush(hand):

def three_of_a_kind(hand):

def two_pair(hand):

def pair(hand):

def high_card(hand):

def evaluate(poker_hand):

poker_hand.sort()

print(poker_hand, "Poker Hand: ", end="")

if royal_flush(poker_hand):

print("Royal Flush")

elif straight_flush(poker_hand):

print("Straight Flush")

elif four_of_a_kind(poker_hand):

print("Four of a Kind")

elif full_house(poker_hand):

print("Full House")

elif flush(poker_hand):

print("Flush")

elif straight(poker_hand):

print("Straight")

elif three_of_a_kind(poker_hand):

print("Three of a Kind")

elif two_pair(poker_hand):

print("Two Pair")

elif pair(poker_hand):

print("One Pair")

else:

print("High Card:", high_card(poker_hand))

def main():

T = 10

J = 11

Q = 12

K = 13

A = 14

print("CSCI 127: Poker Hand Evaluation Program")

print("---------------------------------------")

evaluate([[2, ""], [7, ""], [8, ""], [A, ""], [Q, ""]]) # High card

evaluate([[T, ""], [Q, ""], [6, ""], [9, ""], [Q, ""]]) # One pair

evaluate([[T, ""], [9, ""], [6, ""], [9, ""], [6, ""]]) # Two pair

evaluate([[K, ""], [7, ""], [7, ""], [8, ""], [7, ""]]) # Three of a kind

evaluate([[T, ""], [9, ""], [6, ""], [7, ""], [8, ""]]) # Straight

evaluate([[2, ""], [9, ""], [3, ""], [6, ""], [T, ""]]) # Flush

evaluate([[8, ""], [7, ""], [8, ""], [8, ""], [7, ""]]) # Full house

evaluate([[2, ""], [7, ""], [2, ""], [2, ""], [2, ""]]) # Four of a kind

evaluate([[T, ""], [9, ""], [6, ""], [7, ""], [8, ""]]) # Straight flush

evaluate([[K, ""], [T, ""], [Q, ""], [A, ""], [J, ""]]) # Royal Flush

# -----------------------------------------+

main()

output

image text in transcribed

Logistics - Due Date: Wednesday, December 16 th no later than 11:59 p.m. - Partner Information: You may complete this assignment individually or with exactly one partner. - Submission Instructions (working alone): Upload your solution (py file), entitled YourFirstName-YourLastName-Program2.py to the BrightSpace(D2L) Program 2 Dropbox. - Submission Instructions (working with a partner): Upload your solution (py file), entitled YourFirstName-YourLastName-PartnerFirst.Name-PartnerLastName-Program2.py to the BrightSpace(D2L) Program 2 - Deadline Reminder: Late passes can be used on this assignment. However, if you do not use a late pass and submit it past the deadline, you submission will lose some points (see late assignment policy After 48 hours, the dropbox will close and you will no longer be able to submit In order to complete this lab, you will need to understand - Lists - Iteration - If statements - Functions Poker Hand Representation - A hand consists of five different cards drawn from a 52-card deck. Each card contains a rank (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 or 14) and a suit ("clubs", "diamonds", "hearts" or "spades"). For the ranks, an 11 represents a jack, a 12 represents a queen, a 13 represents a king and a 14 represents an ace. Poker Hand Evaluation - From Best to Worst Note: Cards can appear in any order. - Royal Flush: Contains a 10, jack, queen, king and ace, all of the same suit. For example: king clubs, jack clubs, ace clubs, 10 clubs, queen clubs. - Straight Flush: Contains five consecutive cards that share the same suit. A straight flush does not contain an ace. For example: 3 clubs, 7 clubs, 6 clubs, 4 clubs, 5 clubs. - Four of a Kind: Contains four cards that share the same rank. For example: 4 clubs, 10 diamonds, 4 hearts, 4 spades, 4 diamonds. - Full House: Contains three cards that share the same rank and two cards that share a different rank. For example: jack hearts, king hearts, king clubs, jack clubs, jack diamonds. - Straight: Contains five consecutive cards that do not all share the same suit. For example: 3 clubs, 7 diamonds, 6 hearts, 5 hearts, 4 clubs. - Straight: Contains five consecutive cards that do not all share the same suit. For example: 3 clubs, 7 diamonds, 6 hearts, 5 hearts, 4 clubs. - Three of a Kind: Contains three cards that share the same rank and two cards that have unique ranks. For example: 6 clubs, 7 clubs, 8 clubs, 7 diamonds, 7 hearts. - Two Pair: Contains two cards that share the same rank, two cards that share a different rank, and one card that has a unique rank. For example: six diamonds, six hearts, queen spades, ace clubs, queen diamonds. - Pair: Contains two cards that share the same rank and three cards that have unique ranks. For example: king hearts, queen hearts, 9 diamonds, 9 hearts, ace spades. - Nothing: All other hands of five cards. For example: 9 hearts, 6 diamonds, 3 diamonds, 10 spades, queen clubs. Assignment - Download program2,py, make sure that you fully understand it, and then modify it so that it evaluates poker hands correctly. When it is run using the hands provided, it should produce this output. - The evaluate function is correct - do not modify it. - If it is helpful to do so, you are welcome to introduce other functions into your solution. Hints - Take a look at the get_all_ranks( function. Understand what it does. - Consider thinking about how you can use .count 0 in this assingment - Some functions take in the entire hand, and some functions only take in the ranks. This makes the hand analysis much easier - Notice that the poker hands are sorted right away from lowest ranks to highest ranks. This will also make the hand analysis much easier - Identifying a straight flush and straight will likely be the most difficult. Consider using a for loop SCI 127: Poker Hand Evaluation Program \( [2, '+1,[7, '+'],[8, '+],[12, ' '],[14, '+1] \) Poker Hand: High Card: [14,+1] [6,+1,[9,+1],[10,],[12,+],[12,+1] Poker Hand: One Pair [6,1],[6,+1,[9,+],[9,+1,[10,+1] Poker Hand: Two Pair [6,+],[7,+],[8,+],[9,+],[10,+]] Poker Hand: Straight [2,+1],[2,+],[2,+],[2,+],[7,+]] Poker Hand: Four of a Kind [6,+],[7,+],[8,+],[9,+],[10,+]] Poker Hand: Straight Flush [10,],[11,],[12,],[13,,[14,] ' Poker Hand: Royal Flush Logistics - Due Date: Wednesday, December 16 th no later than 11:59 p.m. - Partner Information: You may complete this assignment individually or with exactly one partner. - Submission Instructions (working alone): Upload your solution (py file), entitled YourFirstName-YourLastName-Program2.py to the BrightSpace(D2L) Program 2 Dropbox. - Submission Instructions (working with a partner): Upload your solution (py file), entitled YourFirstName-YourLastName-PartnerFirst.Name-PartnerLastName-Program2.py to the BrightSpace(D2L) Program 2 - Deadline Reminder: Late passes can be used on this assignment. However, if you do not use a late pass and submit it past the deadline, you submission will lose some points (see late assignment policy After 48 hours, the dropbox will close and you will no longer be able to submit In order to complete this lab, you will need to understand - Lists - Iteration - If statements - Functions Poker Hand Representation - A hand consists of five different cards drawn from a 52-card deck. Each card contains a rank (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 or 14) and a suit ("clubs", "diamonds", "hearts" or "spades"). For the ranks, an 11 represents a jack, a 12 represents a queen, a 13 represents a king and a 14 represents an ace. Poker Hand Evaluation - From Best to Worst Note: Cards can appear in any order. - Royal Flush: Contains a 10, jack, queen, king and ace, all of the same suit. For example: king clubs, jack clubs, ace clubs, 10 clubs, queen clubs. - Straight Flush: Contains five consecutive cards that share the same suit. A straight flush does not contain an ace. For example: 3 clubs, 7 clubs, 6 clubs, 4 clubs, 5 clubs. - Four of a Kind: Contains four cards that share the same rank. For example: 4 clubs, 10 diamonds, 4 hearts, 4 spades, 4 diamonds. - Full House: Contains three cards that share the same rank and two cards that share a different rank. For example: jack hearts, king hearts, king clubs, jack clubs, jack diamonds. - Straight: Contains five consecutive cards that do not all share the same suit. For example: 3 clubs, 7 diamonds, 6 hearts, 5 hearts, 4 clubs. - Straight: Contains five consecutive cards that do not all share the same suit. For example: 3 clubs, 7 diamonds, 6 hearts, 5 hearts, 4 clubs. - Three of a Kind: Contains three cards that share the same rank and two cards that have unique ranks. For example: 6 clubs, 7 clubs, 8 clubs, 7 diamonds, 7 hearts. - Two Pair: Contains two cards that share the same rank, two cards that share a different rank, and one card that has a unique rank. For example: six diamonds, six hearts, queen spades, ace clubs, queen diamonds. - Pair: Contains two cards that share the same rank and three cards that have unique ranks. For example: king hearts, queen hearts, 9 diamonds, 9 hearts, ace spades. - Nothing: All other hands of five cards. For example: 9 hearts, 6 diamonds, 3 diamonds, 10 spades, queen clubs. Assignment - Download program2,py, make sure that you fully understand it, and then modify it so that it evaluates poker hands correctly. When it is run using the hands provided, it should produce this output. - The evaluate function is correct - do not modify it. - If it is helpful to do so, you are welcome to introduce other functions into your solution. Hints - Take a look at the get_all_ranks( function. Understand what it does. - Consider thinking about how you can use .count 0 in this assingment - Some functions take in the entire hand, and some functions only take in the ranks. This makes the hand analysis much easier - Notice that the poker hands are sorted right away from lowest ranks to highest ranks. This will also make the hand analysis much easier - Identifying a straight flush and straight will likely be the most difficult. Consider using a for loop SCI 127: Poker Hand Evaluation Program \( [2, '+1,[7, '+'],[8, '+],[12, ' '],[14, '+1] \) Poker Hand: High Card: [14,+1] [6,+1,[9,+1],[10,],[12,+],[12,+1] Poker Hand: One Pair [6,1],[6,+1,[9,+],[9,+1,[10,+1] Poker Hand: Two Pair [6,+],[7,+],[8,+],[9,+],[10,+]] Poker Hand: Straight [2,+1],[2,+],[2,+],[2,+],[7,+]] Poker Hand: Four of a Kind [6,+],[7,+],[8,+],[9,+],[10,+]] Poker Hand: Straight Flush [10,],[11,],[12,],[13,,[14,] ' Poker Hand: Royal Flush

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

Learn Mysql The Easy Way A Beginner Friendly Guide

Authors: Kiet Huynh

1st Edition

B0CNY7143T, 979-8869761545

More Books

Students also viewed these Databases questions