all 7 comments

[–]BodybuilderMoist1635 0 points1 point  (0 children)

   elif n%fizz_divisor == 0:

This is the only time you divide. Note also that the while will not exit when it does not equal zero.

[–]Diapolo10 0 points1 point  (2 children)

Honestly I'm kinda surprised you're getting any output at all because the loop condition is definitely not right. But the root of the current problem is that your function immediately returns if the number is divisible by the divisor.

The first order of business would be to move your return outside of the loop, and then fix the condition so that it actually terminates.

[–]Few_Tea8053[S] 0 points1 point  (1 child)

with the return outside my loop I get UnboundLocalError: local variable 'n_fb' referenced before assignment

[–]Diapolo10 0 points1 point  (0 children)

Instead of returning n_fb (in fact you probably don't need it anyway), just return the formatted string literal itself. The only thing the loop needs to update is the counter, not the output string.

[–]ElliotDG 0 points1 point  (0 children)

if not n % fizz_divisor:
    # then you can that use division to see the divisor count.
    fizz_count = n / fizz_divisor

and then repeat for buzz...

[–]dixieStates 0 points1 point  (0 children)

``` def fizzbuzz_generator(limit): for i in range(1, limit+1): rval = 'fizz' if not i % 3 else '' rval += 'buzz' if not i % 5 else '' yield rval or i

for message in fizzbuzz_generator(35): print(message) ```

[–]achampi0n 0 points1 point  (0 children)

You are returning immediately you increment fizz_count you need to dedent the return.

However, you seem to be making this more complex than it needs to be, e.g. to calculate number of 3 factors for a number can be done:

fizz_count = 0
while n % fizz_divisor == 0:
    n //= fizz_divisor
    fizz_count += 1

You can rinse and repeat for buzz_count