First, try to store all the elements into a list. Then print the list at the end of the method. You can join the items together with a comma in between using ', '.join(...).
def fizzbuzz(n):
result = []
for x in range(1, n+1):
if x % 3 == 0 and x % 5 == 0:
result.append("fizz buzz")
elif x % 3 == 0:
result.append('fizz')
elif x % 5 == 0:
result.append('buzz')
else:
result.append(str(x))
return result
def main():
print(', '.join(fizzbuzz(20)))
main()
In Python, we have one attribute named end in the print statement that will help you to print your elements horizontally with some space in the end. And I think, with that, it will nearly solve your problem except that the very last item would also have a comma and space at the end, which is not what you desire.