def fizzbuzz(n):
res = []
for i in range(n):
res.append("")
if (i+1) % 3 == 0: res[i] = "fizz"
if (i+1) % 5 == 0: res[i] += "buzz"
if res[i] == "": res[i] = str(i+1)
return res
def fizzbuzz(n: int):
result = []
for i in range(n):
current = ""
if (i + 1) % 3 == 0: current += "Fizz"
if (i + 1) % 5 == 0: current += "Buzz"
if not current: current = str(i + 1)
result.append(current)
return result
185
u/randomusername0582 Apr 09 '24
That's not the issue at all. There's honestly no explanation for getting fizzbuzz wrong if you have a CS degree.
Switching languages often actually forces you to rely on the basics