Skip to content

Commit 0a7ec8a

Browse files
authored
Updated docstrings in exemplar files to use Google style. (exercism#4164)
1 parent ae6554c commit 0a7ec8a

4 files changed

Lines changed: 176 additions & 86 deletions

File tree

exercises/concept/black-jack/.meta/exemplar.py

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
def value_of_card(card):
99
"""Determine the scoring value of a card.
1010
11-
:param card: str - given card.
12-
:return: int - value of a given card. See below for values.
11+
Parameters:
12+
card (str): The given card.
1313
14-
1. 'J', 'Q', or 'K' (otherwise known as "face cards") = 10
15-
2. 'A' (ace card) = 1
16-
3. '2' - '10' = numerical value.
14+
Returns:
15+
int: The value of a given card. See below for values.
16+
17+
1. 'J', 'Q', or 'K' (otherwise known as "face cards") = 10
18+
2. 'A' (ace card) = 1
19+
3. '2' - '10' = numerical value.
1720
"""
1821

1922
if card in ('JQK'):
@@ -31,12 +34,16 @@ def value_of_card(card):
3134
def higher_card(card_one, card_two):
3235
"""Determine which card has a higher value in the hand.
3336
34-
:param card_one, card_two: str - cards dealt in hand. See below for values.
35-
:return: str or tuple - resulting Tuple contains both cards if they are of equal value.
37+
Parameters:
38+
card_one (str): First card dealt in the hand. See below for values.
39+
card_two (str): Second card dealt in the hand. See below for values.
40+
41+
1. 'J', 'Q', or 'K' (otherwise known as "face cards") = 10
42+
2. 'A' (ace card) = 1
43+
3. '2' - '10' = numerical value.
3644
37-
1. 'J', 'Q', or 'K' (otherwise known as "face cards") = 10
38-
2. 'A' (ace card) = 1
39-
3. '2' - '10' = numerical value.
45+
Returns:
46+
str or tuple: The resulting Tuple contains both cards if they are of equal value.
4047
"""
4148

4249
card_one_value = value_of_card(card_one)
@@ -55,14 +62,18 @@ def higher_card(card_one, card_two):
5562

5663

5764
def value_of_ace(card_one, card_two):
58-
"""Calculate the most advantageous value for the ace card.
65+
"""Calculate the most advantageous value for an upcoming ace card.
66+
67+
Parameters:
68+
card_one (str): First card dealt in the hand. See below for values.
69+
card_two (str): Second card dealt in the hand. See below for values.
5970
60-
:param card_one, card_two: str - card dealt. See below for values.
61-
:return: int - either 1 or 11 value of the upcoming ace card.
71+
1. 'J', 'Q', or 'K' (otherwise known as "face cards") = 10
72+
2. 'A' (ace card) = 11 (if already in hand)
73+
3. '2' - '10' = numerical value.
6274
63-
1. 'J', 'Q', or 'K' (otherwise known as "face cards") = 10
64-
2. 'A' (ace card) = 11 (if already in hand)
65-
3. '2' - '10' = numerical value.
75+
Returns:
76+
int: Either 1 or 11, which is the value of the upcoming ace card.
6677
"""
6778

6879
card_one_value = 11 if card_one == 'A' else value_of_card(card_one)
@@ -76,12 +87,16 @@ def value_of_ace(card_one, card_two):
7687
def is_blackjack(card_one, card_two):
7788
"""Determine if the hand is a 'natural' or 'blackjack'.
7889
79-
:param card_one, card_two: str - card dealt. See below for values.
80-
:return: bool - is the hand is a blackjack (two cards worth 21).
90+
Parameters:
91+
card_one (str): First card dealt in the hand. See below for values.
92+
card_two (str): Second card dealt in the hand. See below for values.
8193
82-
1. 'J', 'Q', or 'K' (otherwise known as "face cards") = 10
83-
2. 'A' (ace card) = 11 (if already in hand)
84-
3. '2' - '10' = numerical value.
94+
1. 'J', 'Q', or 'K' (otherwise known as "face cards") = 10
95+
2. 'A' (ace card) = 11 (if already in hand)
96+
3. '2' - '10' = numerical value.
97+
98+
Returns:
99+
bool: Is the hand is a blackjack (two cards worth 21).
85100
"""
86101

87102
return (card_one == 'A' or card_two == 'A') and (value_of_card(card_one) == 10 or value_of_card(card_two) == 10)
@@ -90,8 +105,12 @@ def is_blackjack(card_one, card_two):
90105
def can_split_pairs(card_one, card_two):
91106
"""Determine if a player can split their hand into two hands.
92107
93-
:param card_one, card_two: str - cards dealt.
94-
:return: bool - can the hand be split into two pairs? (i.e. cards are of the same value).
108+
Parameters:
109+
card_one (str): First card in the hand.
110+
card_two (str): Second card in the hand.
111+
112+
Returns:
113+
bool: Can the hand be split into two pairs? (i.e. cards are of the same value).
95114
"""
96115

97116
return value_of_card(card_one) == value_of_card(card_two)
@@ -100,8 +119,12 @@ def can_split_pairs(card_one, card_two):
100119
def can_double_down(card_one, card_two):
101120
"""Determine if a blackjack player can place a double down bet.
102121
103-
:param card_one, card_two: str - first and second cards in hand.
104-
:return: bool - can the hand can be doubled down? (i.e. totals 9, 10 or 11 points).
122+
Parameters:
123+
card_one (str): First card in the hand.
124+
card_two (str): Second card in the hand.
125+
126+
Returns:
127+
bool: Can the hand can be doubled down? (i.e. totals 9, 10 or 11 points).
105128
"""
106129

107130
return 8 < value_of_card(card_one) + value_of_card(card_two) < 12

exercises/concept/card-games/.meta/exemplar.py

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
def get_rounds(number):
88
"""Create a list containing the current and next two round numbers.
99
10-
:param number: int - current round number.
11-
:return: list - current round and the two that follow.
10+
Parameters:
11+
number (int): The current round number.
12+
13+
Returns:
14+
list: The current round number and the two that follow.
1215
"""
1316

1417
return [number, number + 1, number + 2]
@@ -17,9 +20,12 @@ def get_rounds(number):
1720
def concatenate_rounds(rounds_1, rounds_2):
1821
"""Concatenate two lists of round numbers.
1922
20-
:param rounds_1: list - first rounds played.
21-
:param rounds_2: list - second set of rounds played.
22-
:return: list - all rounds played.
23+
Parameters:
24+
rounds_1 (list): The first rounds played.
25+
rounds_2 (list): The second group of rounds played.
26+
27+
Returns:
28+
list: All rounds played.
2329
"""
2430

2531
return rounds_1 + rounds_2
@@ -28,9 +34,12 @@ def concatenate_rounds(rounds_1, rounds_2):
2834
def list_contains_round(rounds, number):
2935
"""Check if the list of rounds contains the specified number.
3036
31-
:param rounds: list - rounds played.
32-
:param number: int - round number.
33-
:return: bool - was the round played?
37+
Parameters:
38+
rounds (list): The rounds played.
39+
number (int): The round number.
40+
41+
Returns:
42+
bool: Was the round played?
3443
"""
3544

3645
return number in rounds
@@ -39,8 +48,11 @@ def list_contains_round(rounds, number):
3948
def card_average(hand):
4049
"""Calculate and returns the average card value from the list.
4150
42-
:param hand: list - cards in hand.
43-
:return: float - average value of the cards in the hand.
51+
Parameters:
52+
hand (list): The cards in the hand.
53+
54+
Returns:
55+
float: The average value of the cards in the hand.
4456
"""
4557

4658
return sum(hand) / len(hand)
@@ -49,8 +61,11 @@ def card_average(hand):
4961
def approx_average_is_average(hand):
5062
"""Return if the (average of first and last card values) OR ('middle' card) == calculated average.
5163
52-
:param hand: list - cards in hand.
53-
:return: bool - does one of the approximate averages equal the `true average`?
64+
Parameters:
65+
hand (list): The cards in the hand.
66+
67+
Returns:
68+
bool: Does one of the approximate averages equal the `true average`?
5469
"""
5570

5671
real_average = card_average(hand)
@@ -68,8 +83,11 @@ def approx_average_is_average(hand):
6883
def average_even_is_average_odd(hand):
6984
"""Return if the (average of even indexed card values) == (average of odd indexed card values).
7085
71-
:param hand: list - cards in hand.
72-
:return: bool - are even and odd averages equal?
86+
Parameters:
87+
hand (list): The cards in the hand.
88+
89+
Returns:
90+
bool: Are the even and odd averages equal?
7391
"""
7492

7593
return card_average(hand[::2]) == card_average(hand[1::2])
@@ -78,8 +96,11 @@ def average_even_is_average_odd(hand):
7896
def maybe_double_last(hand):
7997
"""Multiply a Jack card value in the last index position by 2.
8098
81-
:param hand: list - cards in hand.
82-
:return: list - hand with Jacks (if present) value doubled.
99+
Parameters:
100+
hand (list): The cards in the hand.
101+
102+
Returns:
103+
list: The hand with Jacks (if present) value doubled.
83104
"""
84105

85106
if hand[-1] == 11:

exercises/concept/cater-waiter/.meta/exemplar.py

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@
1313
def clean_ingredients(dish_name, dish_ingredients):
1414
"""Remove duplicates from `dish_ingredients`.
1515
16-
:param dish_name: str - containing the dish name.
17-
:param dish_ingredients: list - dish ingredients.
18-
:return: tuple - containing (dish_name, ingredient set).
16+
Parameters:
17+
dish_name (str): The name of the dish.
18+
dish_ingredients (list): The ingredients for the dish.
19+
20+
Returns:
21+
tuple: Containing (dish_name, ingredient set).
1922
2023
This function should return a `tuple` with the name of the dish as the first item,
2124
followed by the de-duped `set` of ingredients as the second item.
25+
2226
"""
2327

2428
return dish_name, set(dish_ingredients)
@@ -27,12 +31,16 @@ def clean_ingredients(dish_name, dish_ingredients):
2731
def check_drinks(drink_name, drink_ingredients):
2832
"""Append "Cocktail" (alcohol) or "Mocktail" (no alcohol) to `drink_name`, based on `drink_ingredients`.
2933
30-
:param drink_name: str - name of the drink.
31-
:param drink_ingredients: list - ingredients in the drink.
32-
:return: str - drink_name appended with "Mocktail" or "Cocktail".
34+
Parameters:
35+
drink_name (str): Name of the drink.
36+
drink_ingredients (list): Ingredients in the drink.
37+
38+
Returns:
39+
str: drink_name appended with "Mocktail" or "Cocktail".
3340
3441
The function should return the name of the drink followed by "Mocktail" (non-alcoholic) and drink
3542
name followed by "Cocktail" (includes alcohol).
43+
3644
"""
3745

3846
if not ALCOHOLS.isdisjoint(drink_ingredients):
@@ -44,13 +52,16 @@ def check_drinks(drink_name, drink_ingredients):
4452
def categorize_dish(dish_name, dish_ingredients):
4553
"""Categorize `dish_name` based on `dish_ingredients`.
4654
47-
:param dish_name: str - dish to be categorized.
48-
:param dish_ingredients: list - ingredients for the dish.
49-
:return: str - the dish name appended with ": <CATEGORY>".
55+
Parameters:
56+
dish_name (str): The dish to be categorized.
57+
dish_ingredients (set): The ingredients for the dish.
58+
59+
Returns:
60+
str: TThe dish name appended with ": <CATEGORY>".
5061
5162
This function should return a string with the `dish name: <CATEGORY>` (which meal category the dish belongs to).
5263
`<CATEGORY>` can be any one of (VEGAN, VEGETARIAN, PALEO, KETO, or OMNIVORE).
53-
All dishes will "fit" into one of the categories imported from `sets_categories_data.py`
64+
All dishes will "fit" into one of the categories imported from `sets_categories_data.py`.
5465
5566
"""
5667

@@ -69,8 +80,11 @@ def categorize_dish(dish_name, dish_ingredients):
6980
def tag_special_ingredients(dish):
7081
"""Compare `dish` ingredients to `SPECIAL_INGREDIENTS`.
7182
72-
:param dish: tuple - of (dish name, list of dish ingredients).
73-
:return: tuple - containing (dish name, dish special ingredients).
83+
Parameters:
84+
dish (tuple): (dish name, list of dish ingredients).
85+
86+
Returns:
87+
tuple: Containing (dish name, dish special ingredients).
7488
7589
Return the dish name followed by the `set` of ingredients that require a special note on the dish description.
7690
For the purposes of this exercise, all allergens or special ingredients that need to be tracked are in the
@@ -81,12 +95,17 @@ def tag_special_ingredients(dish):
8195

8296

8397
def compile_ingredients(dishes):
84-
"""Create a master list of ingredients.
98+
"""Determine which `dishes` are designated `appetizers` and remove them.
99+
100+
Parameters:
101+
dishes (list): Group of dish names.
102+
appetizers (list): Group of appetizer names.
85103
86-
:param dishes: list - of dish ingredient sets.
87-
:return: set - of ingredients compiled from `dishes`.
104+
Returns:
105+
list: Group of dish names that do not appear on appetizer list.
88106
89-
This function should return a `set` of all ingredients from all listed dishes.
107+
The function should return the list of dish names with appetizer names removed.
108+
Either list could contain duplicates and may require de-duping.
90109
"""
91110

92111
combined_ingredients = set()
@@ -100,9 +119,12 @@ def compile_ingredients(dishes):
100119
def separate_appetizers(dishes, appetizers):
101120
"""Determine which `dishes` are designated `appetizers` and remove them.
102121
103-
:param dishes: list - of dish names.
104-
:param appetizers: list - of appetizer names.
105-
:return: list - of dish names that do not appear on appetizer list.
122+
Parameters:
123+
dishes (list): Group of dish names.
124+
appetizers (list): Group of appetizer names.
125+
126+
Returns:
127+
list: Group of dish names that do not appear on appetizer list.
106128
107129
The function should return the list of dish names with appetizer names removed.
108130
Either list could contain duplicates and may require de-duping.
@@ -114,13 +136,16 @@ def separate_appetizers(dishes, appetizers):
114136
def singleton_ingredients(dishes, intersection):
115137
"""Determine which `dishes` have a singleton ingredient (an ingredient that only appears once across dishes).
116138
117-
:param dishes: list - of ingredient sets.
118-
:param intersection: constant - can be one of `<CATEGORY>_INTERSECTION` constants imported from `sets_categories_data.py`.
119-
:return: set - containing singleton ingredients.
139+
Parameters:
140+
dishes (list): Group of ingredient sets.
141+
intersection (constant): Can be one of `<CATEGORY>_INTERSECTIONS` constants imported from `sets_categories_data.py`.
142+
143+
Returns:
144+
set: Containing singleton ingredients.
120145
121146
Each dish is represented by a `set` of its ingredients.
122147
123-
Each `<CATEGORY>_INTERSECTION` is an `intersection` of all dishes in the category. `<CATEGORY>` can be any one of:
148+
Each `<CATEGORY>_INTERSECTIONS` is an `intersection` of all dishes in the category. `<CATEGORY>` can be any one of:
124149
(VEGAN, VEGETARIAN, PALEO, KETO, or OMNIVORE).
125150
126151
The function should return a `set` of ingredients that only appear in a single dish.

0 commit comments

Comments
 (0)