My project is to create a solitaire game with a different card deck.

I have created four lists with three objecs in each off them and I would like to create 81 unique cards out off these objecs.

colors = [blue, yellow, red]

shapes = [triangel, circle, square]

numbers = [1, 2, 3]

grades = [1, 2, 3]


cards = []

for color in colors:
for form in forms:
for number in numbers:
for grade in grades:
cards.push((color, form, number, grade))

If I want to randomly select three out off these 81 cards. What's the best way to do that?

/Johan

This is how my code look so far. I don't get the lists to work though

class spelkort:

   def __init__(self):
         




       colors = [blue, yellow, red]

       forms = [triangel, circle, square]

       numbers = [1, 2, 3]

       grades = [1, 2, 3]



   cards = []

   for color in colors:
      for form in forms:
         for number in numbers:
            for grade in grades:
               cards.push((color, form, number, grade))

import random
kortutfall = random.sample(cards, 6)

print kortutfall

This one runs

colors = ["blue", "yellow", "red"]
forms = ["triangel", "circle", "square"]
numbers = [1, 2, 3]
grades = [1, 2, 3]
cards = []

for color in colors:
    for form in forms:
        for number in numbers:
            for grade in grades:
                cards.append((color, form, number, grade))

import random
kortutfall = random.sample(cards, 6)

print kortutfall

""" my output -->
[('red', 'circle', 1, 2), ('blue', 'triangel', 1, 2), ('yellow', 'square', 3, 3), ('blue', 'square', 1, 1), ('yellow', 'triangel', 3, 2), ('red', 'circle', 1, 3)]
"""

Hint: don't write code that you don't understand.

Edited 6 Years Ago by Gribouillis: n/a

This question has already been answered. Start a new discussion instead.