from itertools import cycle
fizz = cycle(["","","fizz"])
buzz = cycle(["","","","","buzz"])
for z in zip(fizz,buzz):
print(f"{z[0]}{z[1]}") from itertools import cycle
fizz = cycle(["","","fizz"])
buzz = cycle(["","","","","buzz"])
for z in zip(fizz,buzz):
print(f"{z[0]}{z[1]}")Fizzbuzz is probably the perfect fit, which is sad since it is a synthetic problem. I did find one problem once where I could save about 30s of user waiting time by generating (had to be done dynamically) wheels in the 3-10k element range.
from itertools import cycle
fizz = cycle(["","","fizz"])
buzz = cycle(["","","","","buzz"])
for idx, z in enumerate(zip(fizz,buzz)):
print(f"{idx}: {z[0]}{z[1]}")
Happy now? 1
2
fizz
4
buzz
fizz
You can't just print the number for every line. Check this out - https://rosettacode.org/wiki/FizzBuzz or just run the program in the OP which prints correct output.All I'm saying is that if you water the problem down into something trivial and boring, the solution will be trivial and boring too. No surprise there. The other answers here are more complicated because they solve the canonical FizzBuzz problem, not the boring version of it that is trivial to solve without conditionals.