In the dealCards function i tried to take 7 random cards from the deck list and append it to the hand1. But when i call the function, i indeed get 7 cards but not as string, i get them like this : "<main.UnoCard object at 0x00000202E461DF10>" How can i fix this issue?
import random
class UnoCard:
def __init__(self, color, num):
self.c = color
self.n = num
def __str__(self):
return self.c + " " + str(self.n)
def canplay(self, other):
if self.c == other.c or self.n == other.n:
return True
else:
return False
class CollectionOfUnoCards:
def __init__(self):
self.list1 = []
def addCard(self, c):
self.list1.append(c)
def __str__(self):
s = ""
for card in self.list1:
s += str(card) + "|"
return s
def makeDeck(self):
colors = ["Yellow", "Blue", "Red", "Green"]
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range(1, 3):
for color in colors:
for number in numbers:
card = UnoCard(color, number)
self.addCard(card)
def shuffle(self):
for i in range(1, 400):
random_value = random.randint(0, 71)
deck.list1[0], deck.list1[random_value] = deck.list1[random_value], deck.list1[0]
def dealCards(self):
hand1 = []
for i in range(1, 8):
random_value = random.randint(0, 71)
hand1.append(deck.list1[random_value])
print(hand1)
def getNumCards(self):
print(len(deck.list1))
def getTopCard(self):
print(deck.list1[-1])
deck = CollectionOfUnoCards()
deck.makeDeck()
deck.shuffle()
print(deck)
length = CollectionOfUnoCards()
length.getNumCards()
print(length)
last_card = CollectionOfUnoCards()
last_card.getTopCard()
print(last_card)
player1 = CollectionOfUnoCards()
player1.dealCards()
print(player1)