Re:Beads: Computer language and toolchain
by Jabbles on Thursday May 27, 2021 @12:22PM
(#27304848)
I don't understand your objection.
[ Parent
| on HN ]
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.
Re:Beads: Computer language and toolchain
by alexeldeib on Thursday May 27, 2021 @03:58PM
(#27307491)
as I learned above you can use the "end" kwarg to avoid the newline:
print("Fizz", end="")
Re:Beads: Computer language and toolchain
by CRConrad on Thursday June 03, 2021 @06:21AM
(#27379209)
That doesn't work here, though, because then you don't get "FizzBuzz" for 15 -- you get "Fizz" and "Buzz" on separate lines.
A lot of the rosetta code examples show the simple and the more complex example or less use of built-in functions to show they can express it with the core language.