write an extensible and readable fizzbuzz function in python
- User
write an extensible and readable fizzbuzz function in python
- Assistant
Sure, here's a readable Python function for FizzBuzz:
def fizz_buzz(n): for i in range(1, n+1): if i % 3 == 0 and i % 5 == 0: print('FizzBuzz') elif i % 3 == 0: print('Fizz') elif i % 5 == 0: print('Buzz') else: print(i) fizz_buzz(100)This function loops from 1 to the number
nyou pass it. If the current numberiis divisible by both 3 and 5, it prints 'FizzBuzz'. If it's only divisible by 3, it prints 'Fizz', and if it's only divisible by 5, it prints 'Buzz'. If the number isn't divisible by 3 or 5, it simply prints the number.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.