CPSC120A
Fundamentals of Computer Science I

Lab 33

Classes

Use the command line to create a new directory called lab33 in your labs directory. Make sure all of the .py files that you create for this activity are in that directory.

Card

A great advantage of creating classes is that they facilitate re-use in multiple programs. One class that would be handy to have is a playing card class. It could be used to create many different games.

Details

Create a class called Card in a file called card.py. The Card class should have the following methods:

Example

>>> first_card = Card(1, 1)
>>> second_card = Card(2, 2)
>>> print(first_card)
A♠
>>> print(second_card)
2♣
>>> print(first_card.greater_than(second_card))
False
>>> print(second_card.greater_than(first_card))
True
>>> first_card = Card(10, 3)
>>> second_card = Card(10, 4)
>>> print(first_card)
10♥
>>> print(second_card)
10♦
>>> print(first_card.greater_than(second_card))
False
>>> print(second_card.greater_than(first_card))
False
>>> first_card = Card(0, 0)
>>> print(first_card)
JOKER

Hint

 

Challenge

Create a game using the card class. You could re-create the blackjack game from a previous lab or create a poker game. You may want to add more functions to the class to make implementing the game easier.

Submission

Please show your source code and run your programs for the instructor or lab assistant. Only a programs that have perfect style and flawless functionality will be accepted as complete.