0

so for my problem, I have to create a program that takes a users input, and then prints it like a list. For example, if the user inputs "I like doing this activity, the program should return it as.

I
like
doing
this
activity.

But these should work with any scenario that the user inputs.

I tried using the input function and split to try and define the variables

my_list_of_data = input("Enter your sentence:").split()
print("(%s),/n(%s),/n(%s),/n(%s),/n(%s)"%(my_list_of_data))

I am getting an error in line 2, saying there is not enough arguments to create a string.

6
  • What's the contents of my_list_of_data when you get this error? Commented Jun 10, 2019 at 16:40
  • 1
    print("\n".join(my_list_of_data))? Commented Jun 10, 2019 at 16:40
  • 1
    You're passing a single list to the first %s; % formatting special-cases tuples, so try print("(%s),/n(%s),/n(%s),/n(%s),/n(%s)"%tuple(my_list_of_data)). But now you have the problem of extra parentheses and /n not being a newline... Commented Jun 10, 2019 at 16:41
  • Newline is \n. Commented Jun 10, 2019 at 16:41
  • I was just trying the example above, with I like doing this activity when getting this error, @munk Commented Jun 10, 2019 at 16:42

1 Answer 1

2

Print the list like this:

print('\n'.join(my_list_of_data))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.