Last login: Mon Nov 6 10:33:49 on console Welcome to Darwin! mdhcp5-79:~ mahoney$ python Python 2.3.5 (#1, Mar 20 2005, 20:38:20) [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> cmp(1, 2) -1 >>> cmp(2,1) 1 >>> cmp(1,1) 0 >>> cmp( "hello there", "goodbye" ) 1 >>> a = [ 10, 5, 8, 2 ] >>> dir(a) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__str__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] >>> a.sort() >>> a [2, 5, 8, 10] >>> a.reverse() >>> a [10, 8, 5, 2] >>> b = [10,5,20,4] >>> b.reverse() >>> b [4, 20, 5, 10] >>> c = [ 1, "hi", 3, "three", (10,2), [1,2,3] ] >>> c [1, 'hi', 3, 'three', (10, 2), [1, 2, 3]] >>> c.sort() >>> c [1, 3, [1, 2, 3], 'hi', 'three', (10, 2)] >>> def odd_even_compare(a,b): ... a_is_odd = a % 2 == 1 # true if a is odd ... b_is_odd = b % 2 == 1 # true if b is odd ... if a_is_odd and b_is_even: ... ^D File "", line 4 if a_is_odd and b_is_even: ^ IndentationError: expected an indented block >>> mdhcp5-79:~ mahoney$ python Python 2.3.5 (#1, Mar 20 2005, 20:38:20) [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> def odd_even_compare(a,b) File "", line 1 def odd_even_compare(a,b) ^ SyntaxError: invalid syntax >>> ^D mdhcp5-79:~ mahoney$ l -bash: l: command not found mdhcp5-79:~ mahoney$ ls Desktop Library Music Public Documents Movies Pictures Sites mdhcp5-79:~ mahoney$ cd Desktop/ mdhcp5-79:~/Desktop mahoney$ alias l="ls -sCF" mdhcp5-79:~/Desktop mahoney$ l total 72 8 compare.py 64 graphics.py 0 stuff/ mdhcp5-79:~/Desktop mahoney$ python compare.py [10, 1, 5, 2, 100, 6, 3] [1, 3, 5, 2, 6, 10, 100] mdhcp5-79:~/Desktop mahoney$ l total 96 8 card_stack.py 8 compare.py 8 playing_card.py 8 cards.txt 64 graphics.py 0 stuff/ mdhcp5-79:~/Desktop mahoney$ python playing_card.py - - testing black jack cards - - How many cards? 3 Six of Clubs black jack value is 6 . Ace of Clubs black jack value is 1 . Ace of Diamonds black jack value is 1 . Done. mdhcp5-79:~/Desktop mahoney$ python Python 2.3.5 (#1, Mar 20 2005, 20:38:20) [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> dir() ['__builtins__', '__doc__', '__name__'] >>> print __name__ __main__ >>> print __doc__ None >>> ^D mdhcp5-79:~/Desktop mahoney$ l total 96 8 card_stack.py 8 compare.py 8 playing_card.py 8 cards.txt 64 graphics.py 0 stuff/ mdhcp5-79:~/Desktop mahoney$ python playing_card.py __main__ Exercise 11, chapter 10 of Zelle's "Intro Python" Jim Mahoney, Oct 30 2006 The test at the bottom (printing some random cards) happen if this is run from the command line, either with 'python play_card.py' or './playing_card.py'. The tests won't happen when this is imported from another module. Here are examples of the defined methods for this object. >>> from playing_card import Playing_Card # load it >>> king_of_diamonds = Playing_Card( rank=13, suit='d' ) # create one >>> random_card = Playing_Card() # create random one >>> print king_of_diamonds # convert to string King of Diamonds >>> print king_of_diamonds.getRank() # get rank 13 >>> print king_of_diamonds.getSuit() # get suit d >>> print king_of_diamonds.BJValue() # get blackjack value 10 - - testing black jack cards - - How many cards? Traceback (most recent call last): File "playing_card.py", line 90, in ? n = input(" How many cards? ") EOFError mdhcp5-79:~/Desktop mahoney$ python Python 2.3.5 (#1, Mar 20 2005, 20:38:20) [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import playing_card playing_card Exercise 11, chapter 10 of Zelle's "Intro Python" Jim Mahoney, Oct 30 2006 The test at the bottom (printing some random cards) happen if this is run from the command line, either with 'python play_card.py' or './playing_card.py'. The tests won't happen when this is imported from another module. Here are examples of the defined methods for this object. >>> from playing_card import Playing_Card # load it >>> king_of_diamonds = Playing_Card( rank=13, suit='d' ) # create one >>> random_card = Playing_Card() # create random one >>> print king_of_diamonds # convert to string King of Diamonds >>> print king_of_diamonds.getRank() # get rank 13 >>> print king_of_diamonds.getSuit() # get suit d >>> print king_of_diamonds.BJValue() # get blackjack value 10 >>> ^D mdhcp5-79:~/Desktop mahoney$ l total 104 8 card_stack.py 64 graphics.py 0 stuff/ 8 cards.txt 8 playing_card.py 8 compare.py 8 playing_card.pyc mdhcp5-79:~/Desktop mahoney$ more cards.txt 1 s 3 s 12 d 11 d 2 s mdhcp5-79:~/Desktop mahoney$ python card_stack.py Traceback (most recent call last): File "card_stack.py", line 9, in ? from playing_card import Playing_Card File "/Users/mahoney/Desktop/playing_card.py", line 35 if not rank: ^ IndentationError: unindent does not match any outer indentation level mdhcp5-79:~/Desktop mahoney$ python card_stack.py Traceback (most recent call last): File "card_stack.py", line 9, in ? from playing_card import Playing_Card File "/Users/mahoney/Desktop/playing_card.py", line 35 if not rank: ^ IndentationError: unindent does not match any outer indentation level mdhcp5-79:~/Desktop mahoney$ python card_stack.py Ace of Spades, Two of Diamonds, Three of Clubs Ace of Spades, Three of Spades, Queen of Diamonds, Jack of Diamonds, Two of Spades Ace of Spades, Two of Spades, Three of Spades, Jack of Diamonds, Queen of Diamonds mdhcp5-79:~/Desktop mahoney$ more cards.txt 1 s 3 s 12 d 11 d 2 s mdhcp5-79:~/Desktop mahoney$