Question: Poker problem Download Program 2 . py and rename it according to the instructions above. Once you fully understand it , modify it to evaluate

Poker problem
Download Program2.py and rename it according to the instructions above. Once you fully understand it, modify it to evaluate poker hands correctly. When it is run using the hands provided, it should produce poker output.out.
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.
Poker output:
---------------------------------------
[[10, 'spades'],[11, 'spades'],[12, 'spades'],[13, 'spades'],[14, 'spades']]--> Royal Flush
[[6, 'clubs'],[7, 'clubs'],[8, 'clubs'],[9, 'clubs'],[10, 'clubs']]--> Straight Flush
[[2, 'clubs'],[2, 'diamonds'],[2, 'hearts'],[2, 'spades'],[7, 'clubs']]--> Four of a Kind
[[7, 'clubs'],[7, 'spades'],[8, 'clubs'],[8, 'diamonds'],[8, 'hearts']]--> Full House
[[2, 'diamonds'],[7, 'diamonds'],[8, 'diamonds'],[10, 'diamonds'],[12, 'diamonds']]--> Flush
[[6, 'clubs'],[7, 'clubs'],[8, 'spades'],[9, 'clubs'],[10, 'clubs']]--> Straight
[[7, 'clubs'],[7, 'hearts'],[7, 'spades'],[8, 'clubs'],[13, 'diamonds']]--> Three of a Kind
[[6, 'diamonds'],[6, 'hearts'],[9, 'clubs'],[9, 'diamonds'],[10, 'spades']]--> Two Pair
[[6, 'diamonds'],[9, 'diamonds'],[10, 'spades'],[12, 'clubs'],[12, 'hearts']]--> One Pair
[[2, 'spades'],[7, 'clubs'],[8, 'diamonds'],[11, 'hearts'],[13, 'diamonds']]--> Nothing
program2 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()

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!