Calling Class Methods in Python

0

I'm doing a play of a game of cards and I'm having a problem calling the methods of class Deck() , I've tried to redo some parts of the code and sometimes as an undefined object, I re-do it again and still nothing, could someone help me if possible? Thank you in advance.

Follow the code:

  import random
class Card:
    def __init__(self, rank, suit):
        self.rank = rank
        self.suit = suit

    def getRankeado(self):
        return self.rank

    def getSuit(self):
         return self.suit


class Deck:
    ranks = {'2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'}

    suits = {'ZAP', 'COPAS', 'OURO', 'ESPADA'}

    def __init__(self):
        self.deck = []

        for suit in Deck.suits:
            for rank in Deck.ranks:
                self.deck.append(Card(rank, suit))

    def dealCard(self):
        return self.deck.pop()

    def __repr__(self):
        return self.__repr()

    def lenDeck(self):
        return self.len(Deck)

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

    def imprime(self):
        return print(self.Deck, self.Card)

#saidas

c = Deck()
c.shuffle()
c2 = c.dealCard()
c2.getRank(), c2.getSuit()
    
asked by anonymous 14.06.2018 / 02:26

1 answer

0

Did you notice that the getRank() method was spelled as getRankeado() ? After the fix your program starts working correctly:

import random

class Card(object):

    def __init__(self, rank, suit):
        self.rank = rank
        self.suit = suit

    def getRank(self):
        return self.rank

    def getSuit(self):
         return self.suit

# ... Class Deck() ...

c = Deck()
c.shuffle()
c2 = c.dealCard()

print(c2.getRank(), c2.getSuit())

I've added this print in the last line to display the values of the chosen card.

    
15.06.2018 / 00:38