Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Magic 8 ball txt file list

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading