my code has an issue. I'm relatively new to reading from files, and as such, I don't know what is wrong with my code.
#Read from a file containing questions in the form question, answer
read_file = open('state_capitals.txt','r')
lines = read_file.readlines()
ran_lines = random.randrange(0,49)
string_lines = lines[ran_lines]
global string_lines_split # To make debugging easier
string_lines_split = string_lines.split(',')
print(string_lines_final) # Print correct answer
usr_input = input(string_lines_split)
if usr_input == str(string_lines_split):
First your code has error:
print(string_lines_final) should be
Your problem is that there is a trailing
string_lines_split which causes the comparison failed.
string_lines = lines[ran_lines] to
string_lines = lines[ran_lines].rstrip().