0

I try to print cards shuffled and I already made the set of all poker cards by

class Deck(Cards):

def __init__(self):
    
    self.mycardset = [(f'{y} of {x}') for x in self.suites for y in self.values]

def shuffleDeck(self):
    random.shuffle(self.mycardset)

but when I try to print my cardset shuffled using

def main():

deck = Deck()

print(f'[Current Deck]\n{deck.mycardset}')

shuffled_deck = deck.shuffleDeck()

print(f'[Shuffled Deck]\n{shuffled_deck.mycardset}')
    

There is an error said "none type object has no attribute mycardset."

I think there isn't any wrong spell so mabye there is a gramatical problem but I cant find it. so please let me know how can I print shuffled mycardset not changing the main parts.

  • your method `shuffledeck` does not explicitly return anything (i.e. it returns `None`). as `random.shuffle` shuffles your list in-place it will also return `None`. you could print `deck.mycardset` (or refactor according to what you want). – hiro protagonist May 23 '22 at 19:28
  • @hiroprotagonist thank you for your quick answer. I didnt know no return means return None. so I change the code random.shuffle(self.mycardset) return self.mycardset but it doesent work and said list object has no attribute mycardset. I'd like to use deck.mycardset but I can't:( so let me know what will you change if you can only change the above methods? – 최용준 May 23 '22 at 19:43
  • if you `return self.mycardset` in your `shuffleDeck` method. then you could just use `shuffled_deck = deck.shuffleDeck(); print(shuffled_deck)`. what i proposed was to leave your `shuffleDeck` method as it is and then: `deck.shuffleDeck(); print(deck.mycardset)`. – hiro protagonist May 24 '22 at 06:28

0 Answers0