I need my random responses to be the sentences or strings I have stored in my txt file.
It only prints out a single word instead of the whole line, how can I fix this, thanks.
import random
import time
question = input("Ask the magic 8 ball a question (press enter to quit): ")
while question:
if question == "quit":
break
print("Let's see what your future holds")
print("Let me check real quick")
for i in range(random.randrange(3,10)):
print(". ",end=" ")
time.sleep(1)
print("\nYour answer is")
print("Your future is " + (random.choice(open("responses.txt","r").readline().split())) + " .")
question = input("Ask the magic 8 ball a question (press enter to quit): ")
print("See ya")
response.txt:
It is certain
Without a doubt
You may rely on it
Yes definitely
It is decidedly so
As I see it, yes
Most likely
Yes
Outlook good
Signs point to yes
Reply hazy try again
Better not tell you now
Ask again later
Cannot predict now
Concentrate and ask again
Don’t count on it
Outlook not so good
My sources say no
Very doubtful
My reply is no
>Solution :
The correct way to do it is
print("Your future is " +(random.choice(open("responses.txt","r").read().splitlines())) + " .")
This should solve your problem