Skip to content

Commit 98c308a

Browse files
authored
Updated docstrings for exemlar solutions to follow Google style. (exercism#4162)
1 parent f3cbd46 commit 98c308a

4 files changed

Lines changed: 115 additions & 67 deletions

File tree

exercises/concept/guidos-gorgeous-lasagna/.meta/exemplar.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
def bake_time_remaining(elapsed_bake_time):
1212
"""Calculate the bake time remaining.
1313
14-
:param elapsed_bake_time: int - baking time already elapsed.
15-
:return: int - remaining bake time (in minutes) derived from 'EXPECTED_BAKE_TIME'.
14+
Parameters:
15+
elapsed_bake_time (int): The baking time already elapsed.
16+
17+
Returns:
18+
int: The remaining bake time (in minutes) derived from 'EXPECTED_BAKE_TIME'.
1619
1720
Function that takes the actual minutes the lasagna has been in the oven as
1821
an argument and returns how many minutes the lasagna still needs to bake
@@ -25,11 +28,15 @@ def bake_time_remaining(elapsed_bake_time):
2528
def preparation_time_in_minutes(number_of_layers):
2629
"""Calculate the preparation time.
2730
28-
:param number_of_layers: int - the number of lasagna layers made.
29-
:return: int - amount of prep time (in minutes), based on 2 minutes per layer added.
31+
Parameters:
32+
number_of_layers(int): The number of lasagna layers made.
33+
34+
Returns:
35+
int: Amount of prep time (in minutes), based on 2 minutes per layer added.
3036
3137
This function takes an integer representing the number of layers added to the dish,
3238
calculating preparation time using a time of 2 minutes per layer added.
39+
3340
"""
3441

3542
return number_of_layers * PREPARATION_TIME
@@ -38,13 +45,17 @@ def preparation_time_in_minutes(number_of_layers):
3845
def elapsed_time_in_minutes(number_of_layers, elapsed_bake_time):
3946
"""Calculate the elapsed time.
4047
41-
:param number_of_layers: int - the number of layers in the lasagna.
42-
:param elapsed_bake_time: int - elapsed cooking time.
43-
:return: int - total time elapsed (in in minutes) preparing and cooking.
48+
Parameters:
49+
number_of_layers (int): The number of layers in the lasagna.
50+
elapsed_bake_time (int): Elapsed cooking time.
51+
52+
Returns:
53+
int: Total time elapsed (in minutes) preparing + cooking.
4454
4555
This function takes two integers representing the number of lasagna layers and the
4656
time already spent baking and calculates the total elapsed minutes spent cooking the
4757
lasagna.
58+
4859
"""
4960

5061
return preparation_time_in_minutes(number_of_layers) + elapsed_bake_time

exercises/concept/meltdown-mitigation/.meta/exemplar.py

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
def is_criticality_balanced(temperature, neutrons_emitted):
55
"""Verify criticality is balanced.
66
7-
:param temperature: int or float - temperature value in kelvin.
8-
:param neutrons_emitted: int or float - number of neutrons emitted per second.
9-
:return: bool - is criticality balanced?
10-
11-
A reactor is said to be critical if it satisfies the following conditions:
12-
- The temperature is less than 800 K.
13-
- The number of neutrons emitted per second is greater than 500.
14-
- The product of temperature and neutrons emitted per second is less than 500000.
7+
Parameters:
8+
temperature (int or float): The temperature value in kelvin.
9+
neutrons_emitted (int or float): The number of neutrons emitted per second.
10+
11+
Returns:
12+
bool: Is criticality balanced?
13+
14+
Note:
15+
A reactor is said to be balanced in criticality if it satisfies the following conditions:
16+
- The temperature is less than 800 K.
17+
- The number of neutrons emitted per second is greater than 500.
18+
- The product of temperature and neutrons emitted per second is less than 500000.
19+
1520
"""
1621

1722
output = temperature * neutrons_emitted
@@ -26,21 +31,24 @@ def is_criticality_balanced(temperature, neutrons_emitted):
2631
def reactor_efficiency(voltage, current, theoretical_max_power):
2732
"""Assess reactor efficiency zone.
2833
29-
:param voltage: int or float - voltage value.
30-
:param current: int or float - current value.
31-
:param theoretical_max_power: int or float - power that corresponds to a 100% efficiency.
32-
:return: str - one of ('green', 'orange', 'red', or 'black').
34+
Parameters:
35+
voltage (int or float): Voltage value.
36+
current (int or float): Current value.
37+
theoretical_max_power (int or float): The power level that corresponds to a 100% efficiency.
3338
34-
Efficiency can be grouped into 4 bands:
39+
Returns:
40+
str: One of ('green', 'orange', 'red', or 'black').
3541
36-
1. green -> efficiency of 80% or more,
37-
2. orange -> efficiency of less than 80% but at least 60%,
38-
3. red -> efficiency below 60%, but still 30% or more,
39-
4. black -> less than 30% efficient.
42+
Note:
43+
Efficiency can be grouped into 4 bands:
44+
1. green -> efficiency of 80% or more,
45+
2. orange -> efficiency of less than 80% but at least 60%,
46+
3. red -> efficiency below 60%, but still 30% or more,
47+
4. black -> less than 30% efficient.
4048
41-
The percentage value is calculated as
42-
(generated power/ theoretical max power)*100
43-
where generated power = voltage * current
49+
The percentage value is calculated as
50+
(generated power/ theoretical max power)*100
51+
where generated power = voltage * current
4452
"""
4553

4654
generated_power = voltage * current
@@ -61,14 +69,18 @@ def reactor_efficiency(voltage, current, theoretical_max_power):
6169
def fail_safe(temperature, neutrons_produced_per_second, threshold):
6270
"""Assess and return status code for the reactor.
6371
64-
:param temperature: int or float - value of the temperature in kelvin.
65-
:param neutrons_produced_per_second: int or float - neutron flux.
66-
:param threshold: int or float - threshold for category.
67-
:return: str - one of ('LOW', 'NORMAL', 'DANGER').
72+
Parameters:
73+
temperature (int or float): The value of the temperature in kelvin.
74+
neutrons_produced_per_second (int or float): The neutron flux.
75+
threshold (int or float): The threshold for the category.
76+
77+
Returns:
78+
str: One of ('LOW', 'NORMAL', 'DANGER').
6879
69-
1. 'LOW' -> `temperature * neutrons per second` < 90% of `threshold`
70-
2. 'NORMAL' -> `temperature * neutrons per second` +/- 10% of `threshold`
71-
3. 'DANGER' -> `temperature * neutrons per second` is not in the above-stated ranges
80+
Note:
81+
1. 'LOW' -> `temperature * neutrons per second` < 90% of `threshold`
82+
2. 'NORMAL' -> `temperature * neutrons per second` +/- 10% of `threshold`
83+
3. 'DANGER' -> `temperature * neutrons per second` is not in the above-stated ranges
7284
"""
7385

7486
output = temperature * neutrons_produced_per_second

exercises/concept/plane-tickets/.meta/exemplar.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
def generate_seat_letters(number):
99
"""Generate a series of letters for airline seats.
1010
11-
:param number: int - total number of seat letters to be generated.
12-
:return: generator - generator that yields seat letters.
11+
Parameters:
12+
number (int): Total number of seat letters to be generated.
1313
14-
Seat letters are generated from A to D.
15-
After D it should start again with A.
14+
Returns:
15+
generator: A generator that yields seat letters.
1616
17-
Example: A, B, C, D
17+
Note:
18+
Seat letters are generated from A to D.
19+
After D the sequence starts again with A.
20+
For example: A, B, C, D, A, B
1821
1922
"""
2023

@@ -25,17 +28,18 @@ def generate_seat_letters(number):
2528
def generate_seats(number):
2629
"""Generate a series of identifiers for airline seats.
2730
28-
:param number: int - total number of seats to be generated.
29-
:return: generator - generator that yields seat numbers.
31+
Parameters:
32+
number (int): The total number of seats to be generated.
3033
31-
A seat number consists of the row number and the seat letter.
34+
Returns:
35+
generator: A generator that yields seat numbers.
3236
33-
There is no row 13.
34-
Each row has 4 seats.
37+
Note:
38+
A seat number consists of the row number and the seat letter.
39+
There is no row 13, and each row has 4 seats.
3540
36-
Seats should be sorted from low to high.
37-
38-
Example: 3C, 3D, 4A, 4B
41+
Seats should be sorted from low to high.
42+
For exampl: 3C, 3D, 4A, 4B
3943
4044
"""
4145

@@ -53,10 +57,12 @@ def generate_seats(number):
5357
def assign_seats(passengers):
5458
"""Assign seats to passengers.
5559
56-
:param passengers: list[str] - a list of strings containing names of passengers.
57-
:return: dict - with the names of the passengers as keys and seat numbers as values.
60+
Parameters:
61+
passengers (list[str]): A list of strings containing names of passengers.
5862
59-
Example output: {"Adele": "1A", "Björk": "1B"}
63+
Returns:
64+
dict: With passenger names as keys and seat numbers as values.
65+
Example output: {"Adele": "1A", "Björk": "1B"}
6066
6167
"""
6268

@@ -69,9 +75,12 @@ def assign_seats(passengers):
6975
def generate_codes(seat_numbers, flight_id):
7076
"""Generate codes for a ticket.
7177
72-
:param seat_numbers: list[str] - list of seat numbers.
73-
:param flight_id: str - string containing the flight identifier.
74-
:return: generator - generator that yields 12 character long ticket codes.
78+
Parameters:
79+
seat_numbers (list[str]): A list of seat numbers.
80+
flight_id (str): A string containing the flight identifier.
81+
82+
Returns:
83+
generator: A generator that yields 12 character long ticket codes.
7584
7685
"""
7786

exercises/concept/tisbury-treasure-hunt/.meta/exemplar.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
def get_coordinate(record):
55
"""Return coordinate value from a tuple containing the treasure name, and treasure coordinate.
66
7-
:param record: tuple - with a (treasure, coordinate) pair.
8-
:return: str - the extracted map coordinate.
7+
Parameters:
8+
record (tuple): A (treasure, coordinate) pair.
9+
10+
Returns:
11+
str: The extracted map coordinate.
912
"""
1013

1114
return record[1]
@@ -14,8 +17,11 @@ def get_coordinate(record):
1417
def convert_coordinate(coordinate):
1518
"""Split the given coordinate into tuple containing its individual components.
1619
17-
:param coordinate: str - a string map coordinate
18-
:return: tuple - the string coordinate split into its individual components.
20+
Parameters:
21+
coordinate (str): A string map coordinate.
22+
23+
Returns:
24+
tuple: The string coordinate split into its individual components.
1925
"""
2026

2127
return tuple(coordinate)
@@ -24,9 +30,12 @@ def convert_coordinate(coordinate):
2430
def compare_records(azara_record, rui_record):
2531
"""Compare two record types and determine if their coordinates match.
2632
27-
:param azara_record: tuple - a (treasure, coordinate) pair.
28-
:param rui_record: tuple - a (location, tuple(coordinate_1, coordinate_2), quadrant) trio.
29-
:return: bool - do the coordinates match?
33+
Parameters:
34+
azara_record (tuple): A (treasure, coordinate) pair.
35+
rui_record (tuple): A (location, tuple(coordinate_1, coordinate_2), quadrant) trio.
36+
37+
Returns:
38+
bool: Do the coordinates match?
3039
"""
3140

3241
return convert_coordinate(azara_record[1]) in rui_record
@@ -35,9 +44,12 @@ def compare_records(azara_record, rui_record):
3544
def create_record(azara_record, rui_record):
3645
"""Combine the two record types (if possible) and create a combined record group.
3746
38-
:param azara_record: tuple - a (treasure, coordinate) pair.
39-
:param rui_record: tuple - a (location, coordinate, quadrant) trio.
40-
:return: tuple or str - the combined record (if compatible), or the string "not a match" (if incompatible).
47+
Parameters:
48+
azara_record (tuple): A (treasure, coordinate) pair.
49+
rui_record (tuple): A (location, coordinate, quadrant) trio.
50+
51+
Returns:
52+
tuple or str: The combined record (if compatible), or the string "not a match" (if incompatible).
4153
"""
4254

4355
result = "not a match"
@@ -51,12 +63,16 @@ def create_record(azara_record, rui_record):
5163
def clean_up(combined_record_group):
5264
"""Clean up a combined record group into a multi-line string of single records.
5365
54-
:param combined_record_group: tuple - everything from both participants.
55-
:return: str - everything "cleaned", excess coordinates and information are removed.
66+
Parameters:
67+
combined_record_group (tuple): Everything from both participants.
68+
69+
Returns:
70+
str: Everything "cleaned", excess coordinates and information are removed.
5671
57-
The return statement should be a multi-lined string with items separated by newlines.
72+
Note:
73+
The return statement is a multi-lined string with items separated by newlines.
74+
(see HINTS.md for an example).
5875
59-
(see HINTS.md for an example).
6076
"""
6177

6278
report = ""

0 commit comments

Comments
 (0)