Skip to content

Commit ae6554c

Browse files
authored
Updated docstrings to use Google style. (exercism#4163)
1 parent 98c308a commit ae6554c

4 files changed

Lines changed: 181 additions & 68 deletions

File tree

exercises/concept/currency-exchange/.meta/exemplar.py

Lines changed: 111 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,72 +6,157 @@
66
"""
77

88
def exchange_money(budget, exchange_rate):
9-
"""
9+
"""Calculate estimated value after exchange.
10+
11+
Parameters:
12+
budget (float): Tthe amount of money you are planning to exchange.
13+
exchange_rate (float): The unit value of the foreign currency.
14+
15+
Returns:
16+
float: The exchanged value of the foreign currency you can receive.
17+
18+
Examples:
19+
>>> exchange_money(127.5, 1.2)
20+
106.25
21+
22+
>>> exchange_money(200, 1.10)
23+
181.82
24+
25+
This function calculates and returns the (estimated) value of the exchanged currency.
1026
11-
:param budget: float - amount of money you are planning to exchange.
12-
:param exchange_rate: float - unit value of the foreign currency.
13-
:return: float - exchanged value of the foreign currency you can receive.
1427
"""
1528

1629
return budget / exchange_rate
1730

1831

1932
def get_change(budget, exchanging_value):
20-
"""
33+
"""Calculate currency left after an exchange.
34+
35+
Parameters:
36+
budget (float): The amount of money you own.
37+
exchanging_value (float): The amount of your money you want to exchange now.
38+
39+
Returns:
40+
float: The amount left of your starting currency after the exchange
41+
42+
Examples:
43+
.>>> get_change(127.5, 120.0)
44+
7.5
45+
46+
>>> get_change(300.75, 150.25)
47+
150.50
48+
49+
This function calcultes and returns the amount of money left over from the budget
50+
after an exchange.
2151
22-
:param budget: float - amount of money you own.
23-
:param exchanging_value: float - amount of your money you want to exchange now.
24-
:return: float - amount left of your starting currency after exchanging.
2552
"""
2653

2754
return budget - exchanging_value
2855

2956

3057
def get_value_of_bills(denomination, number_of_bills):
31-
"""
58+
"""Calculate the total value of currency at current denomination.
59+
60+
Parameters:
61+
denomination (int): The value of a single unit (bill).
62+
number_of_bills (int): The total number of units (bills).
63+
64+
Returns:
65+
int: Calculated value of the units (bills).
66+
67+
Examples:
68+
>>> get_value_of_bills(5, 128)
69+
640
70+
71+
>>> get_value_of_bills(15.13, 16)
72+
242
73+
74+
This function calculates and returns the total value of the bills (excluding fractionaal amounts).
3275
33-
:param denomination: int - the value of a bill.
34-
:param number_of_bills: int - total number of bills.
35-
:return: int - calculated value of the bills.
3676
"""
3777

3878
return denomination * number_of_bills
3979

4080

4181
def get_number_of_bills(amount, denomination):
42-
"""
82+
"""Calculate the number of currency units (bills) within the amount.
83+
84+
Parameters:
85+
amount (float): The total starting value.
86+
denomination (int): The value of a single unit (bill).
87+
88+
Returns:
89+
int: The number of units (bills) that can be obtained from the amount.
90+
91+
Examples:
92+
>>> get_number_of_bills(127.5, 5)
93+
25
94+
95+
>>> get_number_of_bills(35.16, 10)
96+
3
97+
98+
This function calcluates and returns the number pf currency units (bills) that can
99+
be obtained from the given amount. Whole bills only - no fractioal amounts.
43100
44-
:param amount: float - the total starting value.
45-
:param denomination: int - the value of a single bill.
46-
:return: int - number of bills that can be obtained from the amount.
47101
"""
48102

49103
return int(amount) // denomination
50104

51105

52106
def get_leftover_of_bills(amount, denomination):
53-
"""
107+
"""Calculate leftover amount after exchanging into bills.
108+
109+
Parameters:
110+
amount (float): The total starting value.
111+
denomination (int): The value of a single unit (bill).
112+
113+
Returns:
114+
float: The amount that is "leftover", given the current denomination.
115+
116+
Examples:
117+
>>> get_leftover_of_bills(127.5, 20)
118+
7.5
119+
120+
>>> get_leftover_of_bills(153.2, 10)
121+
3.20
122+
123+
This function calculates and returns the leftover amount that cannot be
124+
returned from starting amount, due to the currency denomination.
54125
55-
:param amount: float - the total starting value.
56-
:param denomination: int - the value of a single bill.
57-
:return: float - the amount that is "leftover", given the current denomination.
58126
"""
59127

60128
return amount % denomination
61129

62130

63131
def exchangeable_value(budget, exchange_rate, spread, denomination):
64-
"""
132+
"""Calculate the maximum value of the new currency.
133+
134+
Parameters:
135+
budget (float): The amount of your money you are planning to exchange.
136+
exchange_rate (float): The unit value of the foreign currency.
137+
spread (int): The percentage that is taken as an exchange fee.
138+
denomination (int) The value of a single unit (bill).
139+
140+
Returns:
141+
int: The maximum value you can get in the new currency.
65142
66-
:param budget: float - the amount of your money you are planning to exchange.
67-
:param exchange_rate: float - the unit value of the foreign currency.
68-
:param spread: int - percentage that is taken as an exchange fee.
69-
:param denomination: int - the value of a single bill.
70-
:return: int - maximum value you can get.
143+
Examples:
144+
>>> exchangeable_value(127.25, 1.20, 10, 20)
145+
80
146+
147+
>>> exchangeable_value(127.25, 1.20, 10, 5)
148+
95
149+
150+
Note:
151+
The currency denomination is a whole number and cannot be sub-divided.
152+
153+
This function calculates and returns the maximum value of the new currency after
154+
determining the exchange rate plus the spread.
71155
"""
72156

73157
exchange_fee = (exchange_rate / 100) * spread
74158
exchange_value = exchange_money(budget, exchange_rate + exchange_fee)
75159
number_of_bills = get_number_of_bills(exchange_value, denomination)
76160
value_of_bills = get_value_of_bills(denomination, number_of_bills)
161+
77162
return value_of_bills

exercises/concept/currency-exchange/exchange.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def get_change(budget, exchanging_value):
4848
>>> get_change(300.75, 150.25)
4949
150.50
5050
51-
Tthis function calcultes and returns the amount of money left over from the budget
51+
This function calcultes and returns the amount of money left over from the budget
5252
after an exchange.
5353
5454
"""

exercises/concept/ellens-alien-game/.meta/exemplar.py

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,37 @@
44
class Alien:
55
"""Create an Alien object with location x_coordinate and y_coordinate.
66
7-
Attributes
8-
----------
9-
(class)total_aliens_created: int
10-
x_coordinate: int - Position on the x-axis.
11-
y_coordinate: int - Position on the y-axis.
12-
health: int - Number of health points.
13-
14-
Methods
15-
-------
16-
hit(): Decrement Alien health by one point.
17-
is_alive(): Return a boolean to indicate if Alien is alive (if health is > 0).
18-
teleport(new_x_coordinate, new_y_coordinate): Move Alien object to new coordinates.
19-
collision_detection(other): Implementation TBD.
7+
Attributes:
8+
(class) total_aliens_created (int): Total number of Alien instances.
9+
x_coordinate (int): Position on the x-axis.
10+
y_coordinate (int): Position on the y-axis.
11+
health (int): Number of health points.
12+
13+
Methods:
14+
hit(): Decrement Alien health by one point.
15+
is_alive(): Return a boolean for if Alien is alive (if health is > 0).
16+
teleport(new_x_coordinate, new_y_coordinate): Move Alien object to new coordinates.
17+
collision_detection(other): Implementation TBD.
18+
2019
"""
2120

2221
total_aliens_created = 0
2322

2423
def __init__(self, x_coordinate, y_coordinate):
2524
"""Initialize a new Alien object and increment total_aliens_created by 1.
2625
27-
:param x_coordinate: int - Alien position on the x-axis
28-
:param y_coordinate: int - Alien position on the y-axis
26+
Parameters:
27+
x_coordinate (int): Position on the x-axis.
28+
y_coordinate (int): Position on the y-axis.
29+
health (int): Number of health points.
2930
30-
:attribute x_coordinate: int - Alien position on the x-axis
31-
:attribute y_coordinate: int - Alien position on the y-axis
32-
:attribute health: int (3) - Initial Alien health points.
31+
Attributes:
32+
x_coordinate (int): Position on the x-axis.
33+
y_coordinate (int): Position on the y-axis.
34+
health (int): Number of health points. Defaults to 3.
3335
34-
:return: object - New Alien.
36+
Returns:
37+
Alien (Alien Object): New Alien.
3538
"""
3639

3740
Alien.total_aliens_created += 1
@@ -43,7 +46,8 @@ def __init__(self, x_coordinate, y_coordinate):
4346
def hit(self):
4447
"""Decrement Alien health by 1.
4548
46-
:return: None
49+
Returns:
50+
None
4751
"""
4852

4953
#There are two valid interpretations for this method/task.
@@ -54,37 +58,47 @@ def hit(self):
5458
def is_alive(self):
5559
"""Return if the Alien is alive.
5660
57-
:return: boolean
61+
Returns:
62+
bool: Is the Alien Alive?
5863
"""
5964

6065
return self.health > 0
6166

6267
def teleport(self, new_x_coordinate, new_y_coordinate):
6368
"""Change Alien location.
6469
65-
:param new_x_coordinate: int - New location on x-axis.
66-
:param new_y_coordinate: int - New location on y-axis.
70+
Parameters:
71+
new_x_coordinate (int): New location on x-axis.
72+
new_y_coordinate (int): New location on y-axis.
6773
68-
:return: None
74+
Returns:
75+
None
6976
"""
77+
7078
self.x_coordinate = new_x_coordinate
7179
self.y_coordinate = new_y_coordinate
7280

7381
def collision_detection(self, other):
7482
"""Detect collisions with another Alien.
7583
76-
:param other: object - Other Alien object.
84+
Parameters:
85+
other (object): Other Alien object.
7786
78-
:return: None
87+
Returns:
88+
None
7989
"""
8090

8191
pass
8292

93+
8394
def new_aliens_collection(positions):
8495
"""Create a list of Alien instances from a list of coordinate tuples.
8596
86-
:param positions: list - List of tuples of (x, y) coordinates.
97+
Parameters:
98+
positions (list[tuple]): List of (x, y) coordinates in tuples..
8799
88-
:return: list - List of Alien objects.
100+
Returns:
101+
list[object]: List of Alien objects.
89102
"""
103+
90104
return [Alien(position[0], position[1]) for position in positions]

exercises/concept/ghost-gobble-arcade-game/.meta/exemplar.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
def eat_ghost(power_pellet_active, touching_ghost):
55
"""Verify that Pac-Man can eat a ghost if he is empowered by a power pellet.
66
7-
:param power_pellet_active: bool - does the player have an active power pellet?
8-
:param touching_ghost: bool - is the player touching a ghost?
9-
:return: bool - can a ghost be eaten?
7+
Parameters:
8+
power_pellet_active (bool): Does the player have an active power pellet?
9+
touching_ghost (bool): Is the player touching a ghost?
10+
11+
Returns:
12+
bool: Can a ghost be eaten?
13+
1014
"""
1115

1216
return power_pellet_active and touching_ghost
@@ -15,9 +19,13 @@ def eat_ghost(power_pellet_active, touching_ghost):
1519
def score(touching_power_pellet, touching_dot):
1620
"""Verify that Pac-Man has scored when a power pellet or dot has been eaten.
1721
18-
:param touching_power_pellet: bool - is the player touching a power pellet?
19-
:param touching_dot: bool - is the player touching a dot?
20-
:return: bool - has the player scored or not?
22+
Parameters:
23+
touching_power_pellet (bool): Is the player touching a power pellet?
24+
touching_dot (bool): Is the player touching a dot?
25+
26+
Returns:
27+
bool: Has the player scored or not?
28+
2129
"""
2230

2331
return touching_power_pellet or touching_dot
@@ -26,9 +34,12 @@ def score(touching_power_pellet, touching_dot):
2634
def lose(power_pellet_active, touching_ghost):
2735
"""Trigger the game loop to end (GAME OVER) when Pac-Man touches a ghost without his power pellet.
2836
29-
:param power_pellet_active: bool - does the player have an active power pellet?
30-
:param touching_ghost: bool - is the player touching a ghost?
31-
:return: bool - has the player lost the game?
37+
Parameters:
38+
power_pellet_active (bool): Does the player have an active power pellet?
39+
touching_ghost (bool): Is the player touching a ghost?
40+
41+
Returns:
42+
bool: Has the player lost the game?
3243
"""
3344

3445
return not power_pellet_active and touching_ghost
@@ -37,10 +48,13 @@ def lose(power_pellet_active, touching_ghost):
3748
def win(has_eaten_all_dots, power_pellet_active, touching_ghost):
3849
"""Trigger the victory event when all dots have been eaten.
3950
40-
:param has_eaten_all_dots: bool - has the player "eaten" all the dots?
41-
:param power_pellet_active: bool - does the player have an active power pellet?
42-
:param touching_ghost: bool - is the player touching a ghost?
43-
:return: bool - has the player won the game?
51+
Parameters:
52+
has_eaten_all_dots (bool): Has the player "eaten" all the dots?
53+
power_pellet_active (bool): Does the player have an active power pellet?
54+
touching_ghost (bool): Is the player touching a ghost?
55+
56+
Returns:
57+
bool: Has the player won the game?
4458
"""
4559

4660
return has_eaten_all_dots and not lose(power_pellet_active, touching_ghost)

0 commit comments

Comments
 (0)