so, i'm trying to pull a C out of my python class and my final project is killing me. first we had to create the deck of cards using a dictionary and a list. i got that to work.
suits = {0: "Hearts", 1: "Diamonds", 2: "Clubs", 3: "Spades"}
ranks = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
card_deck = []
def create_deck():
for suit in suits:
for rank in ranks:
card_deck.append([rank, suit])
create_deck()
now i have to create a function to associate the list entries with the actual card. so, 1, 0 will read Ace of Hearts and so on. i have no clue clue how to do this. anybody have any suggestions or possibly links? we got hints of:
card = (1,0) index the tuple to get the suit suit=card[1] now take the suit and plug it into the dictionary to get the appropriate text suit_text=suits[suit]
it looks like i need to create a new dictionary with the face cards in it
cards = {1: "Ace", 11: "Jack", 12: "Queen", 13: "King"}
but how do i get them to associate to the list entries??
after some work, i figured it out.
def print_card():
for card in card_deck:
suit = card[1]
suit_text = suits[suit]
if card[0] == 1 or card[0] == 11 or card[0] == 12 or card[0] == 13:
rank = card[0]
rank_text = face_cards[rank]
else:
rank = card[0]
rank_text = ranks[rank] - 1
print (str(rank_text) + " of " + suit_text)
print_card()