So I'm creating an 8 ball program that prompts the user for a question will then spit out a response. The project I have states that the answers must be in txt file, so I created this
file = open("Ball_response.txt","w")
file.write("YES, OF COURSE!")
file.write("WITHOUT A DOUBT, YES")
file.write("YOU CAN COUNT ON IT.")
file.write("FOR SURE!")
file.write("ASK ME LATER")
file.write("I AM NOT SURE")
file.write("I CAN'T TELL YOU RIGHT NOW?")
file.write("I WILL TELL YOU AFTER MY NAP")
file.write("NO WAY!")
file.write("I DON'T THINK SO")
file.write("WITHOUT A DOUBT, NO.")
file.write("THE ANSWER IS CLEARLY NO")
file.close()
The I want to call the list here
import random
# Reading the Ball_response file
def main():
input_file = open('Ball_response.txt', 'r')
line = input_file.readline()
print(line[0])
main()
But when I run the program, it only prints out "Y". I want
0 - Yes, Of Course
1 - Without a Doubt, yes
2 - You can count on it
etc..... How can I accomplish this? I feel like there is something I'm not understanding
n = int(line)will always error since non of the lines are int. Also you are reading only one line then it looks like you are trying to loop through the lines?"YES, OF COURSE!WITHOUT A DOUBT, YESYOU CAN COUNT ON IT.FOR SURE!ASK ME LATERI AM NOT SUREI CAN'T TELL YOU RIGHT NOW?I WILL TELL YOU AFTER MY NAPNO WAY!I DON'T THINK SOWITHOUT A DOUBT, NO.THE ANSWER IS CLEARLY NO"So of course, when you print line[0] you get"Y"