A test project using nbdev
Project description
nbdev_cards
A deck of cards demo of nbdev based on ideas from “Think Python 2nd Edition” by Allen B. Downey.
Install
pip install nbdev-cards2022
additional packages are fastcore
and nbdev
How to use
import the card and deck modules
from nbdev_cards.card import *
from nbdev_cards.deck import *
This lib provids a Card class that you can use to create, display, and compare playing cards.
Card(2,3)
3♥
display all suits
suits
['♣', '♦', '♥', '♠']
display all ranks
ranks
[None, 'A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
Deck class can be called to generate a deck of playing card. Initially, the deck is ordered.
deck = Deck()
deck
A♣; 2♣; 3♣; 4♣; 5♣; 6♣; 7♣; 8♣; 9♣; 10♣; J♣; Q♣; K♣; A♦; 2♦; 3♦; 4♦; 5♦; 6♦; 7♦; 8♦; 9♦; 10♦; J♦; Q♦; K♦; A♥; 2♥; 3♥; 4♥; 5♥; 6♥; 7♥; 8♥; 9♥; 10♥; J♥; Q♥; K♥; A♠; 2♠; 3♠; 4♠; 5♠; 6♠; 7♠; 8♠; 9♠; 10♠; J♠; Q♠; K♠
shuffle()
method could be used to shuffle the deck.
deck.shuffle()
deck
6♠; A♦; 8♣; 3♠; A♣; 7♠; K♥; 9♠; 6♣; A♠; 4♥; 5♦; K♠; 3♣; 3♦; 6♦; 2♦; Q♥; 5♠; 9♦; 2♠; K♣; 7♣; 9♣; 5♣; 10♦; A♥; 8♥; 10♥; 3♥; 4♠; 10♠; J♦; 4♦; 8♠; Q♠; J♠; Q♦; 9♥; 2♣; J♣; 7♥; K♦; 5♥; Q♣; 7♦; J♥; 10♣; 4♣; 2♥; 6♥; 8♦
draw_n()
function can be used to draw n card with or without
replacement.
let’s draw 10 cards with replacement.
draw_n(10, replace=True)
[4♣, 10♥, 4♣, 9♠, K♦, 3♥, 8♠, Q♦, Q♣, 3♠]
now let’s draw 10 cards without replacement.
draw_n(10, replace=False)
[K♦, 4♦, 3♠, Q♦, 7♥, A♦, 4♥, 10♥, 6♠, J♦]
Example: One can draw two sets of cards each set contains four cards and compare to see which one has higher rank.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for nbdev_cards2022-0.0.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d177686207265999c3e3196844fc415200497ff3f3231195a281e5626676cd45 |
|
MD5 | 73ee431d8220d26900e9fe68405d6af7 |
|
BLAKE2b-256 | 59b7401a2802f4971d14ec413f4e92d4bfbeaaef596c47ece2eb964601bf9bb8 |