My 3-line FizzBuzz in python:
for i in range(1, 101): x = [“”, “Fizz”][i%3==0] + [“”, “Buzz”][i%5==0] print([x, i][len(x)==0])
for i in range(1, 101):
x = [“”, “Fizz”][i%3==0] + [“”, “Buzz”][i%5==0]
print([x, i][len(x)==0])
ChatGPT does it in two:
for i in range(1, 101): print(“Fizz” * (i % 3 == 0) + “Buzz” * (i % 5 == 0) or i)
print(“Fizz” * (i % 3 == 0) + “Buzz” * (i % 5 == 0) or i)
And in one:
print(‘\n’.join([‘Fizz’ * (i % 3 == 0) + ‘Buzz’ * (i % 5 == 0) or str(i) for i in range(1, 101)]))
My 3-line FizzBuzz in python:
ChatGPT does it in two:
And in one: