Gemini 2.5 Flash × fizzbuzz
9.7Baseline correctness + code style
correctness 10.0quality 9.0documentation 10.04723ms
$ cat fizzbuzz.prompt — what the model was asked
Write a Python function `fizzbuzz(n: int) -> list[str]` that returns a list of strings for numbers 1 through n: 'Fizz' for multiples of 3, 'Buzz' for multiples of 5, 'FizzBuzz' for multiples of both, and the number as a string otherwise. Include a docstring and at least one usage example.
run 1 of 1
9.7correctness 10.0quality 9.0documentation 10.04723ms
# judge: Correct, clean, well-documented implementation with thorough examples and sensible edge-case handling, only minor nit being the added ValueError not explicitly required by the task.
$ cat gemini-2.5-flash.fizzbuzz.r1.response
```python
def fizzbuzz(n: int) -> list[str]:
"""
Generates a list of strings for numbers 1 through n, following the FizzBuzz rules.
- For multiples of 3, the string is 'Fizz'.
- For multiples of 5, the string is 'Buzz'.
- For multiples of both 3 and 5, the string is 'FizzBuzz'.
- Otherwise, the string is the number itself.
Args:
n (int): The upper limit of the range (inclusive). Must be a non-negative integer.
Returns:
list[str]: A list of strings representing the FizzBuzz sequence.
Raises:
ValueError: If n is a negative integer.
"""
if n < 0:
raise ValueError("Input 'n' must be a non-negative integer.")
results: list[str] = []
for i in range(1, n + 1):
if i % 3 == 0 and i % 5 == 0:
results.append("FizzBuzz")
elif i % 3 == 0:
results.append("Fizz")
elif i % 5 == 0:
results.append("Buzz")
else:
results.append(str(i))
return results
# --- Usage Examples ---
if __name__ == "__main__":
# Example 1: Basic FizzBuzz up to 15
print("FizzBuzz up to 15:")
print(fizzbuzz(15))
# Expected output:
# ['1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz']
print("\n" + "="*30 + "\n")
# Example 2: FizzBuzz up to 5
print("FizzBuzz up to 5:")
print(fizzbuzz(5))
# Expected output:
# ['1', '2', 'Fizz', '4', 'Buzz']
print("\n" + "="*30 + "\n")
# Example 3: FizzBuzz up to 0 (empty list)
print("FizzBuzz up to 0:")
print(fizzbuzz(0))
# Expected output:
# []
print("\n" + "="*30 + "\n")
# Example 4: Demonstrate error handling for negative input
print("Attempting FizzBuzz with a negative number:")
try:
fizzbuzz(-1)
except ValueError as e:
print(f"Caught expected error: {e}")
# Expected output:
# Caught expected error: Input 'n' must be a non-negative integer.
```