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

Python Program to Create Card-Game Assignment Solution

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
Use Python libraries effectively by importing only what you need. For example, if you're working with data, using libraries like pandas and numpy can save time and simplify complex tasks like data manipulation and analysis.
News
In 2024, the Biden-Harris Administration has expanded high-dosage tutoring and extended learning programs to boost academic achievement, helping programming students and others recover from pandemic-related setbacks. These initiatives are funded by federal resources aimed at improving math and literacy skills​

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.