×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Complete Python Solution for Card-Game Assignment

June 15, 2024
Dr. Olivia Campbell
Dr. Olivia
🇺🇸 United States
Python
Dr. Olivia Campbell holds a Ph.D. in Computer Science from the University of Cambridge. With over 800 completed assignments, she specializes in developing complex Python applications, including fitness trackers and exercise planners. Dr. Campbell's expertise lies in algorithm design and data analysis, ensuring optimal performance and accuracy in every project she undertakes.
Key Topics
  • Instructions
    • Objective
  • Requirements and Specifications
Tip of the day
Focus on understanding TensorFlow's computational graph and its eager execution mode. Use pre-built functions like tf.data for efficient data pipelines.
News
The latest version of Google's machine learning library, offering improved performance, streamlined APIs, and expanded support for reinforcement learning, making it a powerful tool for AI development.

Instructions

Objective

Write a program to create card-game in python.

Requirements and Specifications

Instructions:

Suppose we want to be able to place cards back into a deck. Modify the Deck class (will be attached below) to include the operations addTop, addBottom, and addRandom (the last one inserts the card at a random location in the deck). And write unit tests to test the methods suit, suitName and rankNameof Card class in Card.py (Will be attached below).

Source Code

from random import randrange from Card import Card class Deck: #------------------------------------------------------------ def __init__(self): """ Creates a 52 card deck in standard order """ cards = [] for suit in Card.SUITS: for rank in Card.RANKS: cards.append(Card(rank,suit)) self.cards = cards #------------------------------------------------------------ def size(self): """Cards left post: Returns the number of cards in self""" return len(self.cards) #------------------------------------------------------------ def deal(self): """ Deal a single card pre: self.size() > 0 post: Returns the next card, and removes it from self.card if the deck is not empty, otherwise returns False""" if self.size() > 0: return self.cards.pop() else: return False #------------------------------------------------------------ def shuffle(self): """Shuffles the deck post: randomizes the order of cards in self""" n = self.size() cards = self.cards for i,card in enumerate(cards): pos = randrange(i,n) card[i] = card[pos] cards[pos] = card def addTop(self, card: Card): """ Add a card at the top (beginning) of the deck (list of cards) """ self.cards.insert(0, card) def addBottom(self, card: Card): """ Add a card at the bottom (last index) of the deck (list of cards) """ self.cards.append(card) def addRandom(self, card:Card): """ Add a card at a random position of the deck """ self.cards.insert(randrange(0, len(self.cards)-1), card)

Similar Samples

Explore our samples At Programming Homework Help, we offer expertly crafted examples to guide you through your coding challenges. Each sample is designed to clarify complex concepts and enhance your learning experience. Check out our samples to see how we can help you succeed in your programming courses.