Skip to main content

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

or

conda install -c fastai 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nbdev-cards2022-0.0.6.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

nbdev_cards2022-0.0.6-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file nbdev-cards2022-0.0.6.tar.gz.

File metadata

  • Download URL: nbdev-cards2022-0.0.6.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for nbdev-cards2022-0.0.6.tar.gz
Algorithm Hash digest
SHA256 3a0cbbad218923dbcb21a266f02341bfa8db93c939cc649ecb08aeff62152e97
MD5 6182e207965264bfc046d7caa0295aa0
BLAKE2b-256 0f6416bbdd7abe3344aec99756d85dceb3a0f20ec2b728b56af185a0d08585b3

See more details on using hashes here.

File details

Details for the file nbdev_cards2022-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: nbdev_cards2022-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for nbdev_cards2022-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a628b047fbafbc319fea90f0469086ffb294f0c8965d8a71b46009bfca63a59d
MD5 ffbd7d23095bf98449f3ef8795711f44
BLAKE2b-256 68b594e68271fa5f0c1f2c0c782f121c37a453f65f9cf36e90560d091906d54f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page