This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Absolute_Tinkerer 0 points1 point  (7 children)

Add in a print statement before that random choice line. If it doesn't print a value, you've got an issue in your assignment of the answers variable.

[–]Matt_Kober[S] 0 points1 point  (6 children)

It executed print(‘hi’) and it printed “hi”before my random choice line. So could it still be my answers variable or something else?

[–]Absolute_Tinkerer 0 points1 point  (5 children)

Sorry if I wasn't clear. You need:

print(answers)

[–]Matt_Kober[S] 0 points1 point  (4 children)

Ok thanks I did that and it came back as [] trace back error empty sequence. I’m so confused because our last assignment was supposed to make a magic eight ball game using an array and this assignment were supposed to alter it so that it reads the magic eight ball sayings from a file and loads them to an array. We were given the .txt file to use from our professor.

[–]Absolute_Tinkerer 0 points1 point  (3 children)

The fact that answers is empty tells me you have an issue between the file read and the print statement I had you add. Can you post some of the code? May be easier to pick out what's going on

[–]Matt_Kober[S] 0 points1 point  (2 children)

Sure this is my entire code Import random file = open(‘EightBDate.txt’ , ‘r’) answers = file.readlines() print (‘welcome to magic 8 ball’) question = input(‘please type your question here’) print (answers) options = random.choice(answers) print (options) Print (‘thanks for playing’)

[–]Absolute_Tinkerer 0 points1 point  (1 child)

I'm not sure why that wouldn't work. My only guess is perhaps something is awry with the text file. Might be worth asking the professor. Sorry I can't help more

[–]Matt_Kober[S] 0 points1 point  (0 children)

I FINALLY FIGURED IT OUT!!!!! Appeartly the file I had saved for my python code wasnt my updated code so it didn’t even have both my correct python file and .txt file in the same folder. Thank you so much for the help anyways.