Answer to Question #268938 in Python for alb

Question #268938

You decide to create a program suits.py to tally and sort the cards in a hand. You include your earlier functions pick_cards(n) and print_cards(h), plus four new ones: tally(h), which creates and returns a dictionary with suit as key and count as value, sort_cards(h) which creates and returns a dictionary with suit as key and a list of the face values as value, print_tally(t), which prints the tally, and print_sorted(s), which prints the cards in each suit


1
Expert's answer
2021-11-20T06:41:53-0500
from random import shuffle

class Cards:
    def __init__(self):
        values = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
        suites = ['H', 'S', 'C', 'D']
        self.deck = [j + i for j in values for i in suites]

    def shuffle(self):
        shuffle(self.deck)

    def deal(self, n_players):
        self.hands = [self.deck[i::n_players] for i in range(0, n_players)]

c = Cards()
print c.deck
c.shuffle()
print c.deck
c.deal(4)
print c.hands

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS