Printing list elements prints list element addresses

Viewed 15

So I am creating a card game using classes, every time I try to print list elements it prints the address instead which makes the new parts of the game just not work.

class Cards:
  def _init_(self, ranks=2, suits=1):
    self.ranks = ranks
    self.suits = suits

  cardranks = [0, "Ace", '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']
  cardsuits = [0,'Clubs', 'Diamond', 'Heart', 'Spades']

  def returnname(self):
    print(self.cardranks[self.ranks] + ' of ' + self.cardsuits[self.suits])

  def _cmp_(self, other):
    if self.suits > other.suits: print('suit1 is bigger')
    elif self.suits < other.suits: print('suit2 is bigger')
    elif self.ranks > other.ranks: print('rank1 is bigger')
    elif self.ranks < other.ranks: print('rank2 is bigger')
    else: print('both are equal')

class Deck:
  def _init_(self):
    self.cards = []
    for suits in range(4):
        for ranks in range(14):
            self.cards.append((Cards(suits, ranks)))


  def printcards(self):
    for card in self.cards:
        print(str(card))

deck = Deck() deck.printcards()

0 Answers
Related