-5

It takes an input n and outputs the numbers from 1 to n. For each multiple of 3, print "Fizz instead of the number. For each multiple of 5, prints "Buzz" instead of the number. For numbers which are multiples of both 3 and 5, output "FizzBuzz".

You need to make the code to skip the even numbers, so that the logic only applies to odd numbers in the range

Advik
  • 1
  • 2
  • 2
    Does this answer your question? [Python FizzBuzz](https://stackoverflow.com/questions/22743860/python-fizzbuzz) –  Oct 22 '20 at 06:20
  • 1
    Have you tried solving this problem? We're not gonna do your homework here on Stackoverflow. – Joooeey Oct 22 '20 at 06:33
  • Hey Joooeey, I'm not in a coding school that I've homeworks to do. I've tried solving but the was code was printing even numbers too. I've found my mistake now & thanks very much for your helpful comment!! – Advik Oct 29 '20 at 10:00

1 Answers1

1

Adding on to what @dratenik referred, for that last condition to skip for even numbers, you just need to add following :

def fizz_buzz_main(N):
    for i in range(1, N+1):
        if N & 1: # check for odd number, then only call, otherwise skip 
            fizz_buzz() # function already shown by @dratenik

I hope it was clear !

Sample run :
input : n = 10
output : ["1","Fizz","Buzz","7","Fizz"]

SOURAV KUMAR
  • 78
  • 1
  • 8