Need help with Python programming problem.

gk topsoil at mail.com
Sat May 10 08:14:17 EDT 2003


Been trying to get the following problem to work. So far its been 
hectic since i am very new to programming:


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:

2= 2 points
3= 3 points
4= 4 points
5= 5 points
6= 6 points
7= 7 points 
8= 8 points
9= 9 points
10= 10 points
Jack= 11 points
Queen= 12 points
King= 13 points
Ace= 14 points


First the computer picks 3 cards and then the user gets 3 cards. The 
following rules are used to calculate the total points accumulated 
for the computer and the user:

-Each Card carries points equivalent to its rank except the Ace card, 
which is worth 14 points.

-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.


At the end of the game the winner is announced between the computer 
and the user.



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



import random

##Store the deck as a list
Deck = []
UserPoints = 0
CompPoints = 0

##Populate the deck with cards
##Hint - for x in range(14)
##Hint2 - for s in ['hearts', 'spades']

##Shuffle the deck
random.shuffle(deck)

##Main loop
while Deck:
  ##Read 3 cards

  ##calculate points

  ## calculate bonus points

  ## Add points and bonus points to total

  ## etc

##Print winner




Thanks.




More information about the Python-list mailing list