1

I am making a basic bot in Python that you can ask it questions and it will respond. But when I was testing the code (in a 'for' loop), I wanted it to print the result to me word by word, but it prints out the output letter by letter. How do I get it to print word by word? Here's the code;

print("Welcome to your personal  bot assistant.")

question = input('''Ask me anything you want to know
>>> ''')

for i in question:
  print(i)

If I input 'hello' for example, it prints out;

h

e

l

l

o

DrosnickX
  • 425
  • 5
  • 10

1 Answers1

1

Change the for loop to this:

for i in question.split():
    print(i)

This loops through every word in a sentence. For example, the sentence "how old am I" gave me:

how

old

am

I

However, it should be noted that if you used a full stop at the end of the input, the output would include that. To get around that, you can use: question.replace(".", "").

The Pilot Dude
  • 2,091
  • 2
  • 6
  • 24