0

I am currently following along with an intro to Python course. In the course we just wrote the following code.

def fizz_buzz(input):
    if (input % 3 == 0) and (input % 5 == 0):
        return "FizzBuzz"
    if input % 3 == 0:
        return "Fizz"
    if input % 5 == 0:
        return "Buzz"
    return input

print(fizz_buzz(7))

I understand what is happening in the program but I do not understand why it was necessary to set divisor == 0.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 1
    Now would be a great time to learn the difference between assignment (`=`) and testing for equality (`==`) – Useless Oct 28 '22 at 21:29
  • It's not the divisor that is zero, but you are comparing the _remainder_ of the division to zero. In other words, is `input` evenly divisible by 3 or 5. Also, it's a very bad idea to name a variable "input" because `input()` is a built-in function in Python and you are potentially making the input() function unusable in your script. – bfris Oct 28 '22 at 21:52
  • You are only shadowing the built-in function `input` inside `fizz_buzz`. If you have no intention of calling the built-in inside your function, there's no harm in using `input` as the parameter name. – chepner Oct 28 '22 at 21:57

0 Answers0