Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 3: Back to the poker table Write code in python, sagemath Grading criteria: correctness of code. suits = Set([C, D, H, S]) values =

Problem 3: Back to the poker table

Write code in python, sagemath

Grading criteria: correctness of code.

suits = Set(["C", "D", "H", "S"]) values = Set(["A",2,3,4,5,6,7,8,9,"T","J","Q","K"]) cards = cartesian_product([values, suits]) 

hand = Subsets(cards,5)

3a. Write a function which, given two poker hands h1 and h2, returns 1 if h1 is the higher-ranking hand, -1 if h2 is the higher-ranking hand, and 0 if the two hands are equally ranked. Note that poker hands are primarily sorted by their type, but there are rules to break some ties even among hands of the same type. (For example, a pair of queens outranks a pair of jacks.)

3b. Define a Python class called "Hand" with the following property: if s1 and s2 are two poker hands, then

h1 = Hand(s1) h2 = Hand(s2) print(h1 < h2) 

will print True if and only if s2 is (strictly) higher in ranking than s1. Your class should implement the method __lt__ to achieve operator overloading. (Do not implement __cmp__; this works in Python 2 but will fail in Python 3.)

class Hand: # rest of the definition goes here 
# Assume that s1 and s2 are two lists of five distinct cards each. h1 = Hand(s1) h2 = Hand(s2) print(h1 < h2) 

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

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions

Question

2. Whats involved in listening?

Answered: 1 week ago

Question

1. How do listening and hearing diff er?

Answered: 1 week ago