0

I have 40 cards. 10 yellow. 10 red. 10 blue and 10 green. I need to pick 25 random cards, and then give them to 500 people. Each one needs to guess the right color for each of the 25 cards.

This is what I have done so far:

    import random         
    nSuits = 4 # yellow/red/blue/green
    nCards = 25  # Number of random cards
    nPlayers = 500

    def Random_guess():
       randomCards = [random.randrange(nSuits) for i in range(nCards)]
       randomGuesses = [random.randrange(nSuits) for i in range (nPlayers)]

The randomCards works fine according to the shell, but I can't find a way to attribute the random cards to each player and to their guess from the 4 colors. Any suggestion?

Bart
  • 19,692
  • 7
  • 68
  • 77
user1040563
  • 5,121
  • 9
  • 34
  • 36
  • Are the people making their guesses one at a time, or all in advance? Are they aware that there can be at most ten cards of each colour in the deck they are presented with? – Karl Knechtel Nov 17 '11 at 22:22
  • They guess one at a time. Should it make a difference if they didnt?and they don't know that there can be max of 10 cards of each color. – user1040563 Nov 17 '11 at 22:46
  • If they did know, and they guessed one (card, in case that was ambiguous) at a time, then they would not guess a colour they've already seen ten times. – Karl Knechtel Nov 17 '11 at 23:03

3 Answers3

0

if i understand correctly, each player needs 25 guesses (one for each card):

randomGuesses = [[random.randrange(nSuits) for i in range (nCards)] for j in range(nPlayers)]

this will produce a list with nPlayer nested lists, each with nCards "guesses".

randomGuesses[i][j]

is the j'th guess of the i'th player.

yurib
  • 8,043
  • 3
  • 30
  • 55
0

Creating a Class is a great way to have the same thing "own" (or "do") the same thing, across the board.

A common analogy is one of a factory: it's an object factory that produces templates of objects, which then can be customized through attributes, roles, duties, etc.

First, initialize your class:

import random

nSuits = 4 # yellow/red/blue/green
nMaxSuits = 10 # only ten of each yellow, red, blue, green
nCards = 25  # Number of random cards
nPlayers = 500

deck = [suit for suit in range(nMaxSuits) for suit in range(nSuits)]

class CardPerson(object):
    def __init__(self, cards):
        self.cards = cards
    def guess(self):
        #use [deck] list above, it has all good cards
        random.shuffle(self.cards)
        return [self.cards.pop() for i in range(nCards)]

if __name__ == '__main__':
    for x in range(nPlayers):
        person = CardPerson(deck) #you've made your CardPerson...now, get their guesses
        #person.guess() will give you 25 guesses
        #compare it to the cards variable above; if matches >= 17, then...(???)

More info for you:

Getting common elements between two lists that won't use sets (which eliminates duplicates).

Community
  • 1
  • 1
yurisich
  • 6,991
  • 7
  • 42
  • 63
  • yes evetually i need to find out how many of the 500 people have gussed correctly 17 cards or more... – user1040563 Nov 17 '11 at 22:49
  • Ah. An important distinction. 500 people will guess 25 elements, and need to score above 68% accuracy to pass. The odds seem against them! Good luck. – yurisich Nov 17 '11 at 22:56
0

Write a loop which iterates over the 500 players. In the body of the loop, (1) generate 2 random lists of 25 cards each (the 25 cards given to the current user, and her 25 guesses), (2) check each card-guess pair to count the number of good guesses, and (3) storethe result for the current player. After the loop finishes, you will have a list filled with the guess performance of all 500 players.

kol
  • 27,881
  • 12
  • 83
  • 120