0

I am making a card and have them structured like so:

class Cards(IntEnum):
    SIX = 6
    SEVEN = 7
    EIGHT = 8
    NINE = 9
    TEN = 10
    JACK = 11
    QUEEN = 12
    KING = 13
    ACE = 14

class Suit(Enum):
    SPADES = 'spades'
    CLUBS = 'clubs'
    HEARTS = 'hearts'
    DIAMONDS = 'diamonds'

After that I have an init method to combine the two parts into one, I get one full card.

class PlayingCards():
    def __init__(self,card_value,card_suit):
        self.card = card_value
        self.suit = card_suit

When a random set of cards are dealt to a player, I append them to a list and then I print that list. However instead of printing that weird-looking list that prints Cards.SIX Suit.SPADES to ask the user to choose the card they want to play, I want to print 6♠ because it looks nicer, and it's more convenient as a user too. How can I possibly achieve that?

I think I need to relate them back to another class that has the suit equal to its emoji but I'm quite new to python so I need a helping hand.

the whole code is here

import time
from enum import Enum
from random import *
from enum import IntEnum

full_deck = []
partial_deck = []
playerdeck = []
aideck = []

#Creating Enum for each card
class Cards(IntEnum):
    SIX = 6
    SEVEN = 7
    EIGHT = 8
    NINE = 9
    TEN = 10
    JACK = 11
    QUEEN = 12
    KING = 13
    ACE = 14

#Suits of every card
class Suit(Enum):
    SPADES = 'spades'
    CLUBS = 'clubs'
    HEARTS = 'hearts'
    DIAMONDS = 'diamonds'

#Class to hold info for playing cards
class PlayingCards():
    def __init__(self,card_value,card_suit):
        self.card = card_value
        self.suit = card_suit
        
        

#Creating a full deck of cards
def create_deck():
    for x in Suit:  
        
        for i in Cards:
            
            full_deck.append(PlayingCards(Cards(i),Suit(x)))
    return full_deck

def dealingplayers():
    while(len(partial_deck) > 0):
            playerdeck.append(draw_deck(partial_deck))
            aideck.append(draw_deck(partial_deck))


#draw a single card from the deck

def draw_deck(deck):
    
    rand_card = randint(0,len(deck)-1)
    return deck.pop(rand_card)
    


create_deck()
partial_deck = list(full_deck)
dealingplayers()

def game():
    
    for x in range(0,len(playerdeck)):
        
        #GRAPHICAL
        print('You have:')
        
        for x in range(0,len(playerdeck)):
            print(playerdeck[x].card)
        print(len(playerdeck))
        ###############

        #Picking a random number to pick a card
        randomint = randint(0,len(playerdeck)-1)
    
    
        playerscard = playerdeck[randomint].card
        aiscards = aideck[randint(0,len(aideck)-1)].card
    
        if playerscard > aiscards:
            print('WIN!')
        else: print('LOOSE!')
        print('randint =',randomint)
        playerdeck.pop(playerscard)
        aideck.pop(aiscards)


end = False
def test():
    

        for x in range(len(playerdeck)):
            print(x,playerdeck[x].card,playerdeck[x].suit)
            
        player = int(input('Which card do you want to pick?: '))
        try:

            print('You picked: ',playerdeck[player].card,playerdeck[player].suit)
            time.sleep(3)
            playerdeck.pop(player)
            if len(playerdeck) < 1:
                end = False
            else: end = True
        except:
            print('Your Index was out of range!!!')
            time.sleep(2)

        
while end == False:
    test()
  • 2
    Is there any reason why the ``Suit``s are named as themselves, instead of their symbol – as in ``SPADES = 'spades'`` instead of ``SPADES = '♠'``? – MisterMiyagi Nov 23 '20 at 15:12
  • Also relevant: [getting value of enum on string conversion](https://stackoverflow.com/questions/24487405/enum-getting-value-of-enum-on-string-conversion) – Tomerikoo Nov 23 '20 at 15:16
  • Anyway you didn't show the actual code for printing so it's hard to help. I suspect you are doing something like `for card in card_list: print(card.card, card.suit)` – Tomerikoo Nov 23 '20 at 15:18
  • @Tomerikoo hi i put it in – Bunyod Shams Nov 23 '20 at 16:03
  • And what is `playerdeck`? This is still not [mre] – Tomerikoo Nov 23 '20 at 16:05
  • @Tomerikoo i put the whole code down, right now if you run it you can just pick a card and it will delete it from the list, you can try to run it and you will get what I want to do – Bunyod Shams Nov 23 '20 at 16:32
  • i thought that if i put a part of my code it then it would be easier to understand, still new to it, my bad – Bunyod Shams Nov 23 '20 at 16:34

0 Answers0