Intro to
Programming
with Python

Fall 2012
course
navigation

Nov 6

next term

How many of you are interested in the Algorithms course next semester?
Choice of algorithms textbook for next term?

homework

Yes, doing all of this one was a lot of work.
Sounds like there's plenty to talk about here:
Things to think about:
Here's one take on
# -- Card -- card = Card(rank, suit) # rank=1..13, suit='c', 'd', 's', or 'h' = Card() # or this way for a random card print card.getRank() # returns 2 (duece) ... 14 (ace); or card.rank print card.getSuit() # returns 'c', 'd', 'h', or 's'; or card.suit print card # e.g. 'Three of Clubs' card1 < card2 # ordering by (i) rank, (ii) suit sort(cards) # sort a list of cards, low to high, in place # -- Deck -- deck = Deck() # a 52-card deck print len(deck) # number of cards left in the deck card = deck.deal_a_card() # return and remove a random card from deck list = deck.get_n_cards(n) # ditto for a list of cards # -- PokerHand -- hand = PokerHand(string) # make hand from e.g. '1 s, 2 h, 3 d, 4 c, 5 s' = PokerHand(cards=list) # ... from a list of PokerCard's = PokerHand(deck=d) # ... from given deck (and remove 'em from deck) hand = PokerHand() # ... from a new deck hand1 < hand2 # True if hand1 loses to hand2 sort(hands) # sort a list of hands, low to high, in place print hand # e.g. 'Straight Flush : Queen of Hearts, Jack of Hearts, ...' print hand.category # e.g. 'Two Pair' print hand.description # e.g. 'Sixes over Fours'
Let's work on this together in class and see how far we get, as a way to explore both the "object" concept, and to talk about how to think through problems.
We worked on writing something along the lines of the poker hand assignment; I've attached it in its unfinished state.

looking ahead

The end of the term is going to come up quickly. Here's the schedule :
Meanwhile, we will discuss a few other topics (recursion,
http://cs.marlboro.edu/ courses/ fall2012/python/ notes/ Nov_6
last modified Tuesday November 6 2012 11:11 am EST

attachments [paper clip]

     name last modified size
   cards.py Nov 6 2012 11:11 am 2.29kB