Fizz Buzz Implementation | Set 2 | Function to generate FizzBuzz sequence ; Stores count of multiples of 3 and 5 respectively ; Iterate from 1 to N ; Increment count3 by 1 ; Increment count5 by 1 ; Initialize a boolean variable to check if none of the condition matches ; Check if the value of count3 is equal to 3 ; Reset count3 to 0 , and set flag as True ; Check if the value of count5 is equal to 5 ; Reset count5 to 0 , and set flag as True ; If none of the condition matches ; Driver Code
def fizzBuzz ( N ) : NEW_LINE INDENT count3 = 0 NEW_LINE count5 = 0 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT count3 += 1 NEW_LINE count5 += 1 NEW_LINE flag = False NEW_LINE if ( count3 == 3 ) : NEW_LINE INDENT print ( " Fizz " , end = " " ) NEW_LINE count3 = 0 NEW_LINE flag = True NEW_LINE DEDENT if ( count5 == 5 ) : NEW_LINE INDENT print ( " Buzz " , end = " " ) NEW_LINE count5 = 0 NEW_LINE flag = True NEW_LINE DEDENT if ( not flag ) : NEW_LINE INDENT print ( i , end = " " ) NEW_LINE DEDENT print ( end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 15 NEW_LINE fizzBuzz ( N ) NEW_LINE DEDENT