#!/usr/bin/python """ Exercise 11, chapter 10 of Zelle's "Intro Python" Jim Mahoney, Oct 30 2006 So far this is only a skeleton of a working program: I've set up the structure of a class and its methods, along with a loop to test it as specified in the text; however, none of the methods do anything (yet) beyond returning the values for the ace of spades. Code like this is a often a good first step, since it lets you plan the layout of the program first without dealing with all the details. """ class Playing_Card: """ A single playing card. """ def __init__(self, rank, suit): """ rank in range(1,14); suite in ('d', 'c', 'h', 's') """ def getRank(self): """ return rank of card as integer n, 1<=n<=13 """ return 1 def getSuit(self): """ return suit of card as a letter in ('d', 'c', 'h', 's')""" # Note that the problem didn't specifiy form of this return value. # I've chosen to use the same form that __init__ takes. return 's' def BJValue(self): """ Return black jack value of card, 1<= value <= 10. """ return 1 def __str__(self): """ Display card as a string, e.g. 'Ace of Spades'. """ # Here the text implied that an english description is required. return 'Ace of Spades' def random_rank(): """ Return random integer 1 ... 13. """ return 1 def random_suit(): """ Return random suit in ('d', 'c', 'h', 's') """ return 's' # Test by generating and printing n random cards print " - - testing black jack cards - - " n = input(" How many cards? ") for i in range(n): rank = random_rank() suit = random_suit() card = Playing_Card(rank, suit) print print " " + card print " " + "black jack value is " + card.BJValue() + "." print print "Done."