Using Python please create a deck of cards. A card is a tuple containing a numbe
ID: 3802215 • Letter: U
Question
Using Python please create a deck of cards. A card is a tuple containing a number between 1 and 13 representing the cards value and a string contianing "clubs", "diamonds", "hearts", or "spades". Thus the ace of spaces would look like (1, "spades") and the king of diamonds (13, "diamonds") A deck is a list of 13 cards. Your program should create a deck of cards, shuffle it, and then put the first five cards in the deck into a 5 element list which represents a hand. You should write a series of funcitions which return boolean values that can be used to analyze this hand. def is_pair(hand): should return true if there are exactly 2 cards of the same value def is_2_pair(hand): should return true if there is one set of 2 cards with a common value and a second set of 2 cards with a different common value def is_3_ofakind(hand): returns true if there are exactly 3 cards with a comrmon value def is_full_house(hand): returns true if there are 3 cards with a common value and the other cards share a different common value def is_flush(hand): if the five cards all have the same suit def is_straight(hand): returns true if the value of the five cards form a sequence which increases by 1 in each case. For instance (2,"hearts"). (3,"spades"), (4, "diamonds"), (5,"hearts"), (6,"clubs") Your program should create a deck, shuffle it, create a hand from the first five cards, then call each of the above functions and print out which of them return True.
Explanation / Answer
class Deck:
__ranks = ["Ace",2,3 "Jack", "Queen"...]
__suits = ["Spades", "Hearts"...]
deck = []
def __init__(self):
print("this is your deck")
def __new__(self, numOfCards=52):
#here i will create the cards list using for loop
for ....
self.deck =['2 Spades', '2 Hearts', '2 Diamonds', '2 Clubs']
# this will shuffle the deck list after i implicitly created above
self.shuffle()
self.deck= [...][:numOfcards]
# here I am returning the object as a list which is a deck of cards
return self.deck
def shuffle(self):
random.shuffle(self.deck)
from deck import Deck
def game():
cards = Deck(5)
print(cards)
>>> #['2 Spades', '2 Hearts', '2 Diamonds', '2 Clubs'...](list has 21 cards)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.