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:

Implementation Requirements and Hints

  1. For full credit, your program must use functions where appropriate.
  2. If the user enters an invalid rank or suit, print and error message and quit.
  3. 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.
  4. 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.
  5. 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.
  6. Recommended progress:
    1. 9/11 - Complete design and algorithm for entire program. Complete implementation of code to get input from the user.
    2. 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.
    3. 9/22 - Complete implementation of code to sort the cards. Begin implementation of code to determine the hand.
    4. 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

  1. 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.
  2. Make sure that each function is well documented. Your documentation should specify the type and function of the input parameters and output.
  3. 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