0

I have a problem with my code, so I want my output to be:

Baa
Baa, Baa
Baa, Baa, Baa

etc. 10 times over

if the input is: Baa

This is my code:

user_input = str(input("Write something: "))

for i in range(10):
    i += 1
    print(user_input*i)

However this only prints:

Baa
BaaBaa
BaaBaaBaa

And I can't figure out how to add a comma between every word.

  • Does this answer your question? [Python - printing out list separated with comma](https://stackoverflow.com/questions/32796452/python-printing-out-list-separated-with-comma) – Random Davis Sep 21 '20 at 17:14

1 Answers1

0

You can produce a list with multiple elements by using the * operator. Then you can join() them together:

for i in range(10):
    print(', '.join([user_input] * (i + 1)))
quamrana
  • 37,849
  • 12
  • 53
  • 71