cornsnake.util_pick

Functions for randomly selecting text. The pick_one_random function chooses a random text from a list. The pick_one_by_prompt function prompts the user to pick a text from a list.

Documentation

 1"""
 2Functions for randomly selecting text. The `pick_one_random` function chooses a random text from a list. The `pick_one_by_prompt` function prompts the user to pick a text from a list.
 3
 4[Documentation](http://docs.mrseanryan.cornsnake.s3-website-eu-west-1.amazonaws.com/cornsnake/util_pick.html)
 5"""
 6
 7import random
 8
 9
10def pick_one_random(texts):
11    """
12    Function to pick a random text from a list.
13
14    Args:
15    texts (list): A list of texts to choose from.
16
17    Returns:
18    str: A randomly selected text from the list.
19    """
20    return random.choice(texts)
21
22
23def pick_one_by_prompt(texts):
24    """
25    Function to prompt the user to pick a text from a list.
26
27    Args:
28    texts (list): A list of texts to choose from.
29
30    Returns:
31    str: The text selected by the user.
32    """
33    valid_selection = None
34    while not valid_selection:
35        print(texts)
36        selected = input("Please pick one >>")
37        if selected in texts:
38            valid_selection = selected
39    return valid_selection
def pick_one_random(texts):
11def pick_one_random(texts):
12    """
13    Function to pick a random text from a list.
14
15    Args:
16    texts (list): A list of texts to choose from.
17
18    Returns:
19    str: A randomly selected text from the list.
20    """
21    return random.choice(texts)

Function to pick a random text from a list.

Args: texts (list): A list of texts to choose from.

Returns: str: A randomly selected text from the list.

def pick_one_by_prompt(texts):
24def pick_one_by_prompt(texts):
25    """
26    Function to prompt the user to pick a text from a list.
27
28    Args:
29    texts (list): A list of texts to choose from.
30
31    Returns:
32    str: The text selected by the user.
33    """
34    valid_selection = None
35    while not valid_selection:
36        print(texts)
37        selected = input("Please pick one >>")
38        if selected in texts:
39            valid_selection = selected
40    return valid_selection

Function to prompt the user to pick a text from a list.

Args: texts (list): A list of texts to choose from.

Returns: str: The text selected by the user.