Need help with Python programming problem.

Sean 'Shaleh' Perry shalehperry at attbi.com
Sat May 10 09:49:23 EDT 2003


On Saturday 10 May 2003 05:14, gk wrote:
> Been trying to get the following problem to work. So far its been
> hectic since i am very new to programming:
>
>

this is a fairly large problem to start out with for a new programmer.  I 
would highly recommend you break the problem down into smaller, more 
digestible pieces.

it also sounds really similar to homework from a programming class, so direct 
help may not be as useful to you (or others).  Part of learning to program is 
learning to assemble the pieces of a program.

> Make a program that simulates a card game.
> You have a Deck of cards that contains the following:
> -4 suits (spades, hearts, diamonds, clubs)
> -Each suit has 14 ranks and points assigned to them:
>

how would you represent a card in the program? how would you decide what a 
card's value was? its suit?

>
> -If all 3 cards are of the same suit, then add 30 bonus points to the
> total points of the 3 cards.
>
> - If all 3 cards are of the same rank, add 50 points bonus to the
> total points of the 3 cards.
>
> - if all 3 cards are face cards (meaning they have faces like a
> king,queen,jack) and are of the same rank, then add 100 points bonus
> to the total points of the 3 cards.
>
> - if all 3 cards of the same suit are a sequence, add 30 points bonus
> to the total points of the 3 cards.
>

these are simply rules to be applied to 3 cards.  Attack each rule on its own 
and then try to combine them.

>
> The following is what i think should be done (got help on it from
> another forum), but i don't know much syntax and therefore am stuck:
>
> 1) Create somewhere to store the deck of 52 cards (e.g. a list named
> Deck)
> (Hint - search for list.append() and list.pop() help)
> 2) Create somewhere to store user points and computer points
> 3) Fill "Deck" with 52 cards, one of each suite
> 4) Shuffle the deck
> 5) a) Read 3 cards
>    b) Calculate points
>    c) Calculate bonus points
>    d) Add to user or computer store
>    e) Repeat until the deck is empty
> 6) Print scores
>

this sounds reasonable, however, remember to give each player cards (-:

Read the tutorials on the python site, perhaps grab a copy of a python book or 
read one of the online texts.  Then start slowly.  Trying to tackle the whole 
program will just lead to frustration.

I'd start with deciding how i wanted to represent a card and then work on the 
point calculation.  Once a score can be computed for a hand making a game out 
of it just requires wrapping the pieces together.

Since you are new to programming and Python, I would like to recommend to join 
and read the Python tutor mailing list.  It is aimed directly at people in 
your position and has a much lower volume than this list.





More information about the Python-list mailing list