i am worlking on the cards class so it can do several things.
My code is as before but need to change the things to solve given problem
Create a new class Deck that represents a pack of 52 cards. The class should support the following methods:
__init__ ( self ) Creates a deck of cards in standard order.
shuffle(self) Randomizes the order of the cards.
dealCard(self) Returns a single card from the top of the deck, and removes the card from the deck.
cardsLeft(self) Returns the number of cards left in the deck.
Test your class by having it deals out a sequence of n cards where n is a number input by the user. The program should either print out the cards, or display them in a window.
The last code was : -
#card.py
import string
n = input("Enter the value: ")
rank_desc = (None, "Ace", "Two", "Three", "Four") # describe each rank in a tuple
suit_desc = {"s":"Spades ", "h":"Hearts ", "c": "Clubs", "d": "Diamonds"} # describe each suit in a dictionary
class PlayingCard:
def __init__ ( self, rank, suit ): # Creates a card.
self.rank = rank
self.suit = suit
def __str__(self): # Returns a string naming the card. For example: 'Ace of Spades'
return "The %s of %s is worth %d in Blackjack" %(rank_desc[self.rank],
suit_desc[self.suit], self.BJValue())
def getRank(self): #Returns the rank of the card.
return self.rank
def getSuit(self): # Returns the suit of the card.
return self.suit
def BJValue(self): # Returns the 'Blackjack value' of the card (Ace;1, Face card:10)
return min(self.rank, 10)
AceOfSpades = PlayingCard(1, 's')
print AceOfSpades
print AceOfSpades.get Rank()
AceOfHearts = PlayingCard(2, 'h')
print AceOfHearts
print AceOfSpades.get Rank()
AceOfClubs = PlayingCard(3, 'c')
print AceOfClubs
print AceOfSpades.get Rank()
AceOfDiamonds = PlayingCard(4, 'd')
print AceOfDiamonds
print AceOfSpades.get Rank()
what should i change in this code to make it possible and solve out the above given problem?
My code is as before but need to change the things to solve given problem
Create a new class Deck that represents a pack of 52 cards. The class should support the following methods:
__init__ ( self ) Creates a deck of cards in standard order.
shuffle(self) Randomizes the order of the cards.
dealCard(self) Returns a single card from the top of the deck, and removes the card from the deck.
cardsLeft(self) Returns the number of cards left in the deck.
Test your class by having it deals out a sequence of n cards where n is a number input by the user. The program should either print out the cards, or display them in a window.
The last code was : -
#card.py
import string
n = input("Enter the value: ")
rank_desc = (None, "Ace", "Two", "Three", "Four") # describe each rank in a tuple
suit_desc = {"s":"Spades ", "h":"Hearts ", "c": "Clubs", "d": "Diamonds"} # describe each suit in a dictionary
class PlayingCard:
def __init__ ( self, rank, suit ): # Creates a card.
self.rank = rank
self.suit = suit
def __str__(self): # Returns a string naming the card. For example: 'Ace of Spades'
return "The %s of %s is worth %d in Blackjack" %(rank_desc[self.rank],
suit_desc[self.suit], self.BJValue())
def getRank(self): #Returns the rank of the card.
return self.rank
def getSuit(self): # Returns the suit of the card.
return self.suit
def BJValue(self): # Returns the 'Blackjack value' of the card (Ace;1, Face card:10)
return min(self.rank, 10)
AceOfSpades = PlayingCard(1, 's')
print AceOfSpades
print AceOfSpades.get Rank()
AceOfHearts = PlayingCard(2, 'h')
print AceOfHearts
print AceOfSpades.get Rank()
AceOfClubs = PlayingCard(3, 'c')
print AceOfClubs
print AceOfSpades.get Rank()
AceOfDiamonds = PlayingCard(4, 'd')
print AceOfDiamonds
print AceOfSpades.get Rank()
what should i change in this code to make it possible and solve out the above given problem?
Comment