Intro to
Programming
with Python

Fall 2011
course
navigation

nov 3

homework

Go over examples from your last submitted homework, particularly the class/object stuff and the BlackJack assignment.

a Card class

As a group exercise, create a Card class and a short main() program that creates two cards and sees which one is better.
Here's the main() I'd like to use:
cards = [None, None] for i in (0,1): cards[i] = Card() print "card %i is %s" % (i, card) if card[0] > card[1]: print "The first card wins." else: print "The second card wins."
Well, we can, as long as we define a __cmp__ method to tell python how to compare two cards. See http://docs.python.org/reference/datamodel.html#object.__cmp__ for the details; this is a special python class method like __init__ and __str__ .
Discuss the homework assignment, poker hands, and the Hand, Deck, and PokerHand classes. Start setting 'em up their definitions.
Nov 3 after class: I've attached the two python files we worked in in class. Neither has been tested or debugged, so there are likely still syntax errors. The card.py file is a step towards the homework assignment; you can use it if you like, but if so cite it.

euler 55

Depending on time, look at problem 55 from project euler, and think about what pieces of that would fit into an object-oriented programming framework. What sorts of "things" is this about? So what sorts of objects and methods do we need?
http://cs.marlboro.edu/ courses/ fall2011/python/ notes/ nov_3
last modified Thursday November 3 2011 3:15 pm EDT

attachments [paper clip]

     name last modified size
   baseball_diamond.py Nov 3 2011 3:15 pm 2.07kB    card.py Nov 3 2011 3:14 pm 1.91kB