A small module for creating a card deck, used for making card games

Overview

card-deck

This module can be used to create small card games such as BlackJack etc..

To initialize the deck, use:

Deck()

To shuffle the deck, use:

Deck().shuffle()

To restart/renew the deck, use:

Deck().restart()

To draw a card from the deck, use:

Deck().draw()

This returns a list[tuple[str, int]], it could look something like [("Hearts", 5)].

Classes Methods/Properties Paremeters/Arguments
Deck Method: shuffle, draw, restart optional: draw(amount=1), restart(shuffle=True)
Card Properties: name, value, suit required: Card(tuple[str, int])

Try to except EmptyDeckError and CardAmountError when drawing a card since the deck can end up being empty at some point or you maybe try to draw more cards than what the deck has.

Examples

from card_deck import Deck, Card, EmptyDeck

# Instantiating and initializing the deck
deck = Deck()

# Shuffling the deck so it becomes in random orders when drawing a card
deck.shuffle()

# Creating the hand of a player
player_hand = []

while True:
    # Asking if the user wants to draw a card
    inp = input("Do you wanna draw a card? (yes/no): ")
    
    if inp == "yes":
        try:
            player_hand.append(deck.draw())
        except EmptyDeckError: # If the Deck is empty, deck.draw() will raise a EmptyDeckError
            break
    else:
        break

# Lets say we draw a card two times, player_hand would look like: [[("Hearts", 5)], [("Spades", 10)]]
# So what we can do to pretty print it is to iterate through player_hand
for cards in player_hand:
    card = Card(cards[0]) # Since Cards only takes a tuple of str and int, we need to do cards[0]
    print(card.suit, card.name, card.value)
Owner
Hi, I'm 17 (soon 18) and I'm a Python develeoper, currently learning Rust and also working on small Python scripts. Wann be a software engineer in the future :)
A minecraft bedrock server software written in python (3.X)

Podrum README also available in: English 🇺🇸 Français 🇫🇷 Deutsch 🇩🇪 Español 🇪🇸 Tiếng Việt 🇻🇳 Italiana 🇮🇹 Русский 🇷🇺 中文 🇨🇳 Is a Minecraf

Podrum 53 Nov 11, 2022
This repository contains the Unix Game challenges and metadata

This repository contains the Unix Game challenges and metadata

Nokia 7 Apr 06, 2022
Ladder network is a deep learning algorithm that combines supervised and unsupervised learning

This repository contains source code for the experiments in a paper titled Semi-Supervised Learning with Ladder Networks by A Rasmus, H Valpola, M Hon

Curious AI 505 Nov 15, 2022
Wordle player - A Class that plays wordle optimally

wordle_player A Class that plays wordle optimally if you want to play wordle opt

Andrés Hernández 1 Jan 31, 2022
A basic quiz game using Python

QuizGame A basic quiz game using Python Passwords for quizzes (NO CAPS LOCK!): -ryzermattishandsome -canisleepwithyou Before using this, please make s

Austin 1 Nov 12, 2021
A puzzle game coded entirely in Python.

Pyzzle A puzzle game coded entirely in Python. This is a school project created by me, Mohit Singh. The .exe file, created from the main.py script, is

Mohit Singh 1 Mar 19, 2022
A 16x16 clone of Minecraft Classic, written in Python with the Ursina Engine

VoxelCraft A 16x16 clone of Minecraft Classic, written in Python with the Ursina Engine Features:Trees, Water(But there's no gravity, so if you break

2 Jun 23, 2022
A python script that uses pygame to display fractals.

Pygame-Fractals A python script that uses pygame to display interactive fractals. There are 3 fractals on the script. They can be displayed on the col

michel 2 Feb 09, 2022
Follow the numbers - A simple game where the player should follow the numbers and connect the dots

follow_the_numbers This is a simple game where the player should follow the numb

Sammy Mishinev 3 Nov 22, 2022
Utility.py - a utility that offerres cool cli tools and games.

Utilty.py Utility.py is a utility that offerres cool cli tools and games. Currently the offerd games/items are: get the number, countdown, random name

bee-micizi 1 Dec 08, 2021
Easily manage wine prefixes in a new way. Run Windows software and games on Linux

Bottles Easily manage wineprefix using environments Documentation · Forums · Telegram group · Funding 📚 Documentation Before opening a new issue, che

Bottles 4.1k Jan 09, 2023
uses Entropy to find the best next guess for Wordle, given the color clues

WordleSolver uses Entropy to find the best next guess for Wordle, given the color clues use player.py and enter in the string for the suggested clue w

Steve Earth 1 Jan 26, 2022
A Cataclysm: Dark Days Ahead launcher with additional features

CDDA Game Launcher A Cataclysm: Dark Days Ahead launcher with additional features. Download here. Implemented features Launching the game Detecting th

Rémy Roy 402 Jan 02, 2023
Console 2D GameEngine {C2DGE} [0.1.0]

Console 2D GameEngine {C2DGE} [0.1.0] By Grosse pastèque#6705 The Project's Goal : This projects was just a challenge so if you have bad reviews, it's

Big watermelon 1 Nov 06, 2021
Python Interactive Mini Games

Python Interactive Mini Games Mini projects from Coursera's An Introduction to I

Ashish Choudhary 1 Jan 16, 2022
Bingo game now in python play as much you want :) no need to give me credit it's open as fuck

Bingo-py-game A game coded with Python Introduction This is a Terminal-based game currently in its initial stage. I am working on adding more efficien

Frey 5 Aug 12, 2021
BritishTrainsDepartureBoard - A pygame program that immitates the dot matrix departure screens found at National Rail stations

BritishTrainsDepartureBoard - A pygame program that immitates the dot matrix departure screens found at National Rail stations

Finn O'Neill 3 Aug 10, 2022
Jiminy, fast and portable Python/C++ simulator of poly-articulated systems with OpenAI Gym interface for reinforcement learning.

Jiminy is a fast and portable cross-platform open-source simulator for poly-articulated systems. It was built with two ideas in mind: provide a fast y

Alexis DUBURCQ 122 Dec 29, 2022
Este repositorio es creado con el fin de brindar soporte a las personas que están en el proceso de aprendizaje MISIONTIC 2022 en la universidad de Antioquia

Este repositorio es creado con el fin de brindar soporte a las personas que están en el proceso de aprendizaje MISIONTIC 2022 en la universidad de Antioquia. Hecho por los estudiantes para los estudi

Andrés Mauricio Gómez 11 Jun 22, 2022
Hangman Game

Hangman Game Este juego fue creado a partir de los conocimientos adquiridos en el Curso de Python: Comprehensions, Lambdas y Manejo de Errores que exi

Carlos Valencia 2 Nov 14, 2022