Project 1 - Poker Helper
Due - Friday, September 29, 2006
The goal of this project is to give you experience using
conditionals and functions in Python. You will write a program
that takes as input the suit and rank of three playing cards and
informs the user of the type of 3-card poker
hand he/she is holding. Following is a sample run of the program:
pinot:~/teaching/cs110/test_py srollins$ python compare.py
Enter the rank of card 1: Q
Enter the suit of card 1: Hearts
Enter the rank of card 2: 10
Enter the suit of card 2: Diamonds
Enter the rank of card 3: J
Enter the suit of card 3: Hearts
***************************
You are holding a straight
***************************
Valid card ranks, in order of increasing value, are as follows: 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A. Valid card suits are as follows: Spades, Diamonds, Hearts, Clubs. The ranking of hands, from highest to lowest is as follows:
- Straight Flush - All cards have the same suit and the ranks are in sequence (e.g., 2,3,4 or 10,J.Q).
- Three of a Kind - All cards have the same rank.
- Straight - The ranks of the cards are in sequence.
- Flush - All cards have the same suit.
- Pair - Two of the three cards have the same rank.
Implementation Requirements and Hints
- For full credit, your program must use functions where
appropriate.
- If the user enters an invalid rank or suit, print and error
message and quit.
- If a hand can be classified into more than one category,
print the highest ranking category into which it falls. For
example, 2-Hearts, 3-Hearts, 4-Hearts would be classified as a
Straight Flush, not just a Straight or a Flush.
- You may want to convert the rank into a numerical value to
make comparison easier. For example, 2=2, 3=3, ..., J=11, Q=12, K=13,
A=14.
- You may want to sort the cards before determining the
hand. Recall that 2, 3, 4 is a straight and so is 4, 2, 3.
-
Recommended progress:
- 9/11 - Complete design and algorithm for entire program.
Complete implementation of code to get input from the user.
- 9/18 - Complete implementation of code to verfiy that user
input is valid. Complete implementation of code to convert the
rank entered to a numerical value.
- 9/22 - Complete implementation of code to sort the
cards. Begin implementation of code to determine the hand.
- 9/29 - Complete implementation of code to determine the
hand.
Extra Credit Opportunity
For extra credit, allow the user to enter two hands, compare them
and print the winner. In order to accomplish this, you will need
to modify your program such that it can compare two hands that
fall into the same category. For example, a pair of 10's would
beat a pair of 4's.
Due 1:30PM Friday September 29, 2006
- Complete and submit your working code. Turn in a hard copy in class and place a copy of your .py file in the submit directory /home/submit/cs110/username.
- Make sure that each function is well documented. Your documentation should specify the type and function of the input parameters and output.
- Run your program on a variety of inputs ensuring that all error conditions are handled correctly.
Note: No portion of your code may be copied from any other
source including another text book, a web page, or another
student (current or former). You must provide citations for any
sources you have used in designing and implementing your program.
Sami Rollins