Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Poker hand test To solve this problem, you need to understand the following Python concepts: lists, functions, loops and if statements. Your program will be

Poker hand test
To solve this problem, you need to understand the following Python concepts: lists, functions, loops and if statements.
Your program will be tested on a different set of poker hands than the ones that appear in the main() function of poker.py. Thus, it is important that you test your program on different inputs and identify the different types of poker hands in a general fashion.
5 points - Every royal flush is identified correctly. (All or nothing.)
5 points - Every straight flush is identified correctly. (All or nothing.)
5 points - Every four of a kind is identified correctly. (All or nothing.)
10 points - Every full house is identified correctly. (All or nothing.)
10 points - Every flush is identified correctly. (All or nothing.)
10 points - Every straight is identified correctly. (All or nothing.)
10 points - Every three of a kind is identified correctly. (All or nothing.)
10 points - Every two pair is identified correctly. (All or nothing.)
10 points - Every pair is identified correctly. (All or nothing.)
10 points - Every nothing is identified correctly. (All or nothing.)
15 points - The Python solution is properly commented, easy to understand, high quality and does not contain unnecessary code. (3 points for each type of improvement up to 15 points.)
Python Poker Code:
def royal_flush(hand):
return False
def straight_flush(hand):
return False
def four_of_a_kind(hand):
return False
def full_house(hand):
return False
def flush(hand):
return False
def straight(hand):
return False
def three_of_a_kind(hand):
return False
def two_pair(hand):
return False
def one_pair(hand):
return False
# -----------------------------------------------+
# Evaluate |
# -----------------------------------------------+
# poker_hand: a 5-card poker hand, represented |
# as a list of lists, e.g.[[7, 'clubs'],...]|
# -----------------------------------------------+
# Return a string, the poker hand evaluation. |
# Do not change this function. |
# -----------------------------------------------+
def evaluate(poker_hand):
""" Return the string evaluation of a 5-card poker hand """
poker_hand.sort() # Sort the cards into ascending order
if royal_flush(poker_hand):
return "Royal Flush"
elif straight_flush(poker_hand):
return "Straight Flush"
elif four_of_a_kind(poker_hand):
return "Four of a Kind"
elif full_house(poker_hand):
return "Full House"
elif flush(poker_hand):
return "Flush"
elif straight(poker_hand):
return "Straight"
elif three_of_a_kind(poker_hand):
return "Three of a Kind"
elif two_pair(poker_hand):
return "Two Pair"
elif one_pair(poker_hand):
return "One Pair"
else:
return "Nothing"
# -----------------------------------------------+
def main():
""" Controls the logic of the poker hand evaluation """
print("CSCI 127: Poker Hand Evaluation Program")
print("---------------------------------------")
hand1=[[10, "spades"],[14, "spades"],[12, "spades"],[13, "spades"],[11, "spades"]] # royal flush
hand2=[[10, "clubs"],[9, "clubs"],[6, "clubs"],[7, "clubs"],[8, "clubs"]] # straight flush
hand3=[[2, "diamonds"],[7, "clubs"],[2, "hearts"],[2, "clubs"],[2, "spades"]] # 4 of a kind
hand4=[[8, "diamonds"],[7, "clubs"],[8, "hearts"],[8, "clubs"],[7, "spades"]] # full house
hand5=[[13, "diamonds"],[7, "diamonds"],[2, "diamonds"],[8, "diamonds"],[10, "diamonds"]] # flush
hand6=[[10, "clubs"],[9, "clubs"],[6, "clubs"],[7, "clubs"],[8, "spades"]] # straight
hand7=[[13, "diamonds"],[7, "clubs"],[7, "hearts"],[8, "clubs"],[7, "spades"]] # 3 of a kind
hand8=[[10, "spades"],[9, "clubs"],[6, "diamonds"],[9, "diamonds"],[6, "hearts"]] # 2 pair
hand9=[[10, "spades"],[12, "clubs"],[6, "diamonds"],[9, "diamonds"],[12, "hearts"]] # 1 pair
hand10=[[2, "spades"],[7, "clubs"],[8, "diamonds"],[13, "diamonds"],[11, "hearts"]] # nothing
hands =[hand1, hand2, hand3, hand4, hand5, hand6, hand7, hand8, hand9, hand10]
for hand in hands:
print(hand,"-->", evaluate(hand))
# -----------------------------------------------+
main()
example output:
hand1=[[10, "clubs"],[14, "clubs"],[12, "clubs"],[13, "clubs"],[11, "clubs"]] # royal flush
hand2=[[13, "clubs"],[12, "clubs"],[11, "clubs"],[10, "clubs"],[9, "clubs"]] # straight flush
hand3=[[9, "diamonds"],[9, "clubs"],[9, "hearts"],[2, "clubs"],[9, "spades"]] # 4 of a kind
hand4=[[8, "diamonds"],[7, "clubs"],[8, "hearts"],[8, "clubs"],[7, "spades"]] # full house
hand5=[[13, "hearts"],[7, "hearts"],[2, "hearts"],[8, "hear

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

Students also viewed these Databases questions

Question

7 What evidence of mediation do you see from your tasks?

Answered: 1 week ago

Question

What do you mean by underwriting of shares ?

Answered: 1 week ago

Question

Define "Rights Issue".

Answered: 1 week ago

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Explain the procedure for valuation of shares.

Answered: 1 week ago

Question

to encourage a drive for change by developing new ideas;

Answered: 1 week ago

Question

4 What are the alternatives to the competences approach?

Answered: 1 week ago