Question: Python Project. Add code were it is commented to add code follow the commented instructions some of it i have already filled in just need

 Python Project. Add code were it is commented to add code follow the commented instructions some of it i have already filled in just need help with the others from comparable import Comparable class Card(Comparable): """ This immutable class represents a Comparable playing Card, inheriting from the Comparable class, The private instance variables are rank and suit. The number of compares are not kept. Here Aces are low and Kings are high Only Rank is used for comparison Suit: Clubs = 0 Diamonds = 1 Hearts = 2 Spades = 3 Rank: Ace = 1 2-10 = 2-10 Jack = 11 Queen = 12 King = 13 """ def __init__(self, suit, rank): """ Constructor: Initializes rank and suit from the parameters """ self.__suit = int(suit) self.__rank = int(rank) ''' Add code here''' def get_rank(self): """ Return rank """ ''' Add code here''' return self.__rank def get_suit(self): """ Return suit """ ''' Add code here''' return self.__suit def compare(self, otherCard): """ Compares this card to other by Rank, Aces low Returns a positive number if self is greater than otherCard Returns a negative number if self is less than otherCard Otherwise returns 0, if Cards are equal """ ''' Add code here''' if self.__rank > otherCard.get_rank(): return 1 if self.__rank < otherCard.get_rank(): return -1 if self.__rank == otherCard.get_rank(): return 0 def __str__(self): """ Returns a string representation of the Card, as rank-suit Use a tuple with string representations of the Suit As "C" = Clubs, "D" = Diamonds, "H" = Heats, "S" = Spades Use a tuple with string representations of the Rank As "A" = Aces, "J" = Jacks, "Q" = Queens, "K" = Kings Let the first element of the tuple be None Use the rank and suit of the Card as indexes into the tuples """ suits = ("C", "D", "H", "S") ranks = (None, "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K") ''' Add code here''' 
import random from card import Card class Deck(list): """ This class represents a Deck of Cards. It inherits from list - it is a list Cards are added at the end of the list: Use append Cards are dealt from the end of the list: Use pop() """ def __init__(self): """ Constructor: Calls the list constructor """ ''' Add code here''' super().__init__() def initialize(self): """ Initializes the Deck with 52 Cards Both the Suits and Ranks are integers Suits: 0=Clubs, 1=Diamonds, 2=Hearts, 3=Spades Ranks: 1=Ace, 2-10=2=10, 11=Jacks, 12=Queen, 13=King """ ''' Add code here''' def add_card(self, card): """ Add the Card to the end of the list """ ''' Add code here''' def deal(self): """ Removes and returns the last Card in the list That's what gamblers call dealing from the bottom of the deck """ ''' Add code here''' def shuffle(self): """ The random class has a shuffle method that accepts a list as an argument Use it to shuffle the Deck No return needed """ ''' Add code here''' def __str__(self): """ Returns a string containing the list of Cards in the Deck: 13 Cards to a line The newline character is added for every 13th Card """ ''' Add code here''' 
from card import Card from linkedList import LinkedList class Hand(LinkedList): """ This represents a Player's Hand in the game. It inherits from LinkedList - it is a LinkedList. The Player holds the Hand as an instance variable. The Player controls the Hand calling the LinkedList methods. """ def __init__(self): """ Constructor: Calls the LinkedList constructor """ ''' Add code here''' def __str__(self): """ Returns a string containing the list of Cards in the Hand: 13 Cards to a line The newline character is added for every 13th Card. """ hand_str = "" current = self._head for c in range(len(self)): hand_str += "{} ".format(current.data) if (c+1) % 13 == 0: hand_str += ' ' current = current.next return hand_str 
from card import Card from linkedList import LinkedList class Pile(LinkedList): """ This class represents a Pile of Cards on the table. It inherits from LinkedList - it is a LinkedList. The Cards are added and removed at the front of the Pile. """ def __init__(self): """ Constructor: Calls the LinkedList constructor. """ ''' Add code here''' def add_card(self, card): """ Adds the Card to the front of the list """ ''' Add code here''' def remove_card(self): """ Removes and returns the Card at the front of the list """ ''' Add code here''' def top_two_cards(self): """ Retrieves the 1st two nodes and returns the Cards Return Player1 Card, Player2 Card: Watch out for the correct order """ ''' Add code here''' def __str__(self): """ Returns the Cards in the Pile as a string by calling the __str__ method of the Card object, starting with the first Card as: Rank-Suit Rank-Suit Rank-Suit etc """ ''' Add code here''' 
from hand import Hand from pile import Pile class Player: """ This class represents a Player of the game The Player holds his Hand as an instance variable, The Hand is a LinkedList of Cards. When a Player is dealt a Card from the Deck, the Card is added first in his Hand When a Player adds a Pile after becoming the winner, the Pile of Cards is added last to the Hand, one at a time Cards are only played from the front of the Hand """ def __init__(self): """ Constructor: Creates the empty hand """ ''' Add code here''' def add_card(self, card): """ Add the passed in Card to the Hand at the front """ ''' Add code here''' def add_pile(self, pile): """ Add the passed in Pile of Cards to the Hand at the back. The Cards are removed from the Pile and added to the Hand - one at a time """ ''' Add code here''' def play_card(self, pile): """ Remove the top Card from the Hand And add it to the passed in Pile Use a method from the Pile class """ ''' Add code here''' def get_num_cards(self): """ Return the number of Cards in the Hand """ ''' Add code here''' def display_hand(self): """ Display the Player's Hand by calling the __str__ method """ ''' Add code here''' 
class Node(): """ This class represents the Node of the LinkedList. The instance variables are public for simplicity. There is no need for getters or setters. The instances variables of this class include: 1. self.data: holds the data for the Node. 2. self.next: holds the pointer to the next Node. The class methods include: a. __init__: This method is the constructor and it initializes each instance variable. b. __str__: This method returns the data instance variable as a string. """ def __init__(self, item): """ Constructor: Sets the data instance variable to the item parameter Sets the next instance variable to None """ ''' Add code here from slides ''' self.data = item self.next = None def __str__(self): """ Returns the data instance variable as a string """ ''' Add code here from slides ''' return str(self.data) class LinkedList: """ This class is an implementation of the Singly LinkedList ADT where both a head pointer and a tail pointer are used. The number of Nodes in the list is kept and updated as Nodes are added and removed. It uses protected instance variables, so that the child classes can get direct access. The instances variables of this class include: 1. self._head: holds a pointer to the first Node. 2. self._tail: holds a pointer to the last Node. 3. self._size: hold the number of Nodes on the LinkedList The class methods include: a. __init__: This method is the constructor. It initializes the protected instance variables. b. __len__: This method returns the number of Nodes in the LinkedList. c. is_empty: This method returns True, if the LinkedList is empty and False, otherwise. d. add_first: This method creates a new Node with the passed in item and adds the Node as the first Node of the LinkedList. e. add_last: This method creates a new Node with the passed in item and adds the Node as the last Node of the LinkedList. f. remove_first: This method removes the first Node of the LinkedList and returns it g. __str__(self): This method returns the data of the LinkedList as a string """ def __init__(self): """ Constructor: Uses protected instance variables Sets the head instance variable to None Sets the tail instance variable to None Sets the linked list size to 0 """ ''' Add code here from slides ''' self._head = None self._tail = None self._size = 0 def __len__(self): """ Returns the number of Nodes in the LinkedList. """ ''' Add code here from slides ''' return self._size def is_empty(self): """ Returns True, if LinkedList is empty. Returns False, otherwise. """ ''' Add code here from slides ''' if len(self) == 0 : return True else: return False def add_first(self, item): """ Creates a new Node with the given item. Adds the Node as the first element of the LinkedList. Updates both the head and tail pointers. Increments the number of Nodes in the LinkedList. """ ''' Add code here from slides ''' new_node = Node(item) new_node.next = self._head self._head = new_node if self.is_empty(): self._tail = new_node self._size += 1 def add_last(self, item): """ Creates a new Node with the given item. Adds the Node as the last element of the LinkedList. Call add_first, if thre list is empty. Updates both the head and tail pointers. Increments the number of Nodes in the LinkedList. """ ''' Add code here from slides ''' if self.is_empty(): self.add_first(item) else: new_node = Node(item) self._tail.next = new_node self._tail = new_node self._size += 1 def remove_first(self): """ Removes the 1st Node of the LinkedList and returns its data. Returns None, if LinkedList is empty. Updates both the head and tail pointers. Decrements the number of Nodes in the LinkedList. """ ''' Add code here from slides ''' if self.is_empty(): return None current = self._head self._head = current.next self._size -= 1 if self.is_empty(): self._tail = None return current.data def __str__(self): """ Return the contents of the LinkedList as a string with each Node's data on a separate line starting with the head of the LinkedList. """ ''' Add code here from slides ''' data_str = "" current = self._head for d in range(len(self)): data_str += str(current.data) + " " current = current.next return data_str 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!