Skip to content

Commit 9d95fc8

Browse files
authored
Rename parameter 'n' to 'num' in fizz_buzz function for better readability
1 parent 26b083a commit 9d95fc8

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed
Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1-
"""FizzBuzz Problem.
1+
def fizz_buzz(num: int) -> list[str]:
2+
"""FizzBuzz Problem.
23
3-
This module contains a solution to the classic FizzBuzz problem.
4-
For numbers 1 to n, print 'Fizz' for multiples of 3, 'Buzz' for
5-
multiples of 5, and 'FizzBuzz' for multiples of both.
6-
"""
7-
8-
9-
def fizz_buzz(n: int) -> list[str]:
10-
"""
11-
Return a list of FizzBuzz results for numbers from 1 to n.
12-
13-
For each number from 1 to n:
14-
- Return 'FizzBuzz' if divisible by both 3 and 5
15-
- Return 'Fizz' if divisible by 3
16-
- Return 'Buzz' if divisible by 5
4+
- Return "Fizz" if the number is divisible by 3
5+
- Return "Buzz" if the number is divisible by 5
6+
- Return "FizzBuzz" if the number is divisible by both 3 and 5
177
- Return the number as a string otherwise
188
199
Args:
20-
n: Positive integer representing the range
10+
num: Positive integer representing the range
2111
2212
Returns:
2313
A list of strings containing FizzBuzz results
2414
2515
Raises:
26-
ValueError: If n is not a positive integer
16+
ValueError: If num is not a positive integer
2717
2818
Examples:
2919
>>> fizz_buzz(5)
@@ -34,17 +24,18 @@ def fizz_buzz(n: int) -> list[str]:
3424
>>> fizz_buzz(0)
3525
Traceback (most recent call last):
3626
...
37-
ValueError: n must be a positive integer
27+
ValueError: num must be a positive integer
3828
>>> fizz_buzz(-5)
3929
Traceback (most recent call last):
4030
...
41-
ValueError: n must be a positive integer
31+
ValueError: num must be a positive integer
4232
"""
43-
if not isinstance(n, int) or n <= 0:
44-
raise ValueError("n must be a positive integer")
33+
34+
if not isinstance(num, int) or num <= 0:
35+
raise ValueError("num must be a positive integer")
4536

4637
result = []
47-
for i in range(1, n + 1):
38+
for i in range(1, num + 1):
4839
if i % 15 == 0:
4940
result.append("FizzBuzz")
5041
elif i % 3 == 0:
@@ -59,5 +50,4 @@ def fizz_buzz(n: int) -> list[str]:
5950

6051
if __name__ == "__main__":
6152
import doctest
62-
6353
doctest.testmod()

0 commit comments

Comments
 (0)