3 ms·
I think he's saying that inside of the loop in FizzBuzz, it should look like something like this (Python-esque pseudocode, assuming for a second print() doesn't
by OskarS 5y ago
I think he's saying that inside of the loop in FizzBuzz, it should look like something like this (Python-esque pseudocode, assuming for a second print() doesn't add a newline automatically):
if x % 3 == 0:
print("Fizz")
if x % 5 == 0:
print("Buzz")
if x % 3 != 0 and x % 5 != 0:
print(x)
print("\n")
i.e. no special "FizzBuzz" case for when it's divisible by 15, it just naturally falls out of the first two if's. It's a bit of a silly objection though, the it's fine to write it as the author did.
- alexeldeib 5y agoas I learned above you can use the "end" kwarg to avoid the newline: print("Fizz", end="")
- CRConrad 5y agoThat doesn't work here, though, because then you don't get "FizzBuzz" for 15 -- you get "Fizz" and "Buzz" on separate lines.