May 2019
Beginner
528 pages
29h 51m
English
Our next example presents two custom classes that you can use to shuffle and deal a deck of cards. Class Card represents a playing card that has a face ('Ace', '2', '3', …, 'Jack', 'Queen', 'King') and a suit ('Hearts', 'Diamonds', 'Clubs', 'Spades'). Class DeckOfCards represents a deck of 52 playing cards as a list of Card objects. First, we’ll test-drive these classes in an IPython session to demonstrate card shuffling and dealing capabilities and displaying the cards as text. Then we’ll look at the class definitions. Finally, we’ll use another IPython session to display the 52 cards as images using Matplotlib. We’ll show you where to get nice-looking public-domain card images.
Read now
Unlock full access