コード例 #1
0
ファイル: game.py プロジェクト: Heithoff/challenges
def draw_letters():
    """Pick NUM_LETTERS letters randomly. Hint: use stdlib random"""
    k = min(NUM_LETTERS, len(POUCH))
    draw = random.sample(POUCH, k)
    for letter in draw:
        POUCH.remove(letter)
    return draw
コード例 #2
0
def draw_letters(num_letters):
    letters = []
    for _ in range(num_letters):
        idx = rd.randint(0, len(POUCH))
        letters.append(POUCH[idx])
        POUCH.remove(POUCH[idx])
    return letters
コード例 #3
0
ファイル: game.py プロジェクト: tanzyy96/challenges
def draw_letters():
    """Pick NUM_LETTERS letters randomly. Hint: use stdlib random"""
    letters = []
    for i in range(NUM_LETTERS):
        draw = random.choice(POUCH)
        POUCH.remove(draw)
        letters.append(draw)
    return letters
コード例 #4
0
def draw_letters():
    """Pick NUM_LETTERS letters randomly. Hint: use stdlib random"""
    draw = []
    for num in range(NUM_LETTERS):
        rand_choice = POUCH.pop(random.choice(range(len(POUCH))))
        draw.append(rand_choice)
    return draw
コード例 #5
0
def draw_letters():
    # pull letters from bag
    my_letters = []
    for i in range(7):
        position = random.randint(0, len(POUCH) - 1)
        # print(i, position, POUCH[position])
        my_letters.append(POUCH.pop(position))
    return my_letters
コード例 #6
0
ファイル: game.py プロジェクト: seantibor/challenges
def draw_letters():
    """Draw 7 letters from POUCH"""
    me_pouch = list()
    pouch_len = len(POUCH)
    for _ in range(0, 7):
        position = random.randint(0, pouch_len - 1)
        me_pouch.append(POUCH.pop(position))
        pouch_len = pouch_len - 1
    return me_pouch
コード例 #7
0
def draw_letters():
    letters = []
    for count in range(1, 8):
        letter = random.choice(POUCH)
        # Got a letter, need to remove it from POUCH so same letter is not drawn 2x
        for x in POUCH:
            if letter == x:
                idx = POUCH.index(x)
                del POUCH[idx]
                break
        letters.append(random.choice(POUCH))

    # Check if drawn letters are only vowels, redraw if so
    if _all_vowels(letters):
        print('Only vowels, repicking...')
        draw_letters()
    print("Letters drawn: {}".format(' '.join(letters)))
    return letters
コード例 #8
0
ファイル: game.py プロジェクト: Vyzef/desafio-Coisas
def draw_letters():
    return [POUCH.pop().lower() for x in range(NUM_LETTERS)]
コード例 #9
0
ファイル: game.py プロジェクト: jboynyc/challenges
def draw_from_pouch(n):
    """Pop n randomly chosen letters out of pouch."""
    shuffle(POUCH)
    for _ in range(n):
        yield POUCH.pop()