Hi!
I'm working on a solitaire game, with a different card deck. First I create a big list with 81 elements (cards in this case), cardList. From this list, six cards are ramdomly picked and put into another list, playerCardList, and printed on the court.

Once the cards are printed the player is asked to remove three cards. I would like these cards to be removed from cardList so they don't appear again. I would also like them to be put into a new list where I can compare them to one another.

1. class Kortlek():
   2.     def __init__(self,colors=[], forms=[], numbers=[], grades=[]):
   3.         self.cardList = []
   4.         self.playerCardList = []
   5.         for color in colors:
   6.             for form in forms:
   7.                 for number in numbers:
   8.                     for grade in grades:
   9.                         tmp= Kort(color, form, number, grade)
  10.                         self.cardList.append(tmp)
  11.  
  12.     def cards(self):
  13.         for a in random.sample(self.cardList, 6):
  14.             self.playerCardList.append(a)
  15.  
  16.         self.write()
  17.  
  18.         self.question()
  19.  
  20.     def question(self):
  21.         val = raw_input("Would you like to remove three cards?\n1.Yes\n2.Quit\n")
  22.         if val == "1":
  23.             for kort in range(3):
  24.                 txt = "Write the number of card " + str(card) + ":\n"
  25.                 kortID = int(raw_input(txt))
  26.                 try:
  27.                     self.playerCardList.pop(kortID-1)
  28.                 except IndexError:
  29.                     print "That card is not in your pile"
  30.                     kortID = int(raw_input(txt))
  31.                     self.playerCardList.pop(kortID-1)
  32.  
  33.  
  34.             self.addCard()
  35.  
  36.         elif val == "2":
  37.             quit()
  38.  
  39.         else:
  40.             print "Pick either 1 or 2"
  41.  
  42.  
  43.  
  44.     def addCard(self):
  45.         for a in random.sample(self.cardList, 3):
  46.             self.playerCardList.append(a)
  47.  
  48.         self.write()
  49.         self.question()
  50.  
  51.     def write(self):
  52.         for b in self.playerCardList:
  53.             b.visa()
  54.  
  55. def cardShuffle():
  56.     card = Kortlek(["blue   ", "yellow ", "red    "],["triangel", "circle  ", "square  "],[1, 2, 3],[1, 2, 3])
  57.     card.cards()
  58.  
  59.  
  60.

your paste came with line numbers. who wrote this class?

repaste again well... ;)

You also should test for length before you draw cards:

def cards(self):
    if len(self.cardList) > 5):
        for a in random.sample(self.cardList, 6):
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.