print("No.\tCountries\t\t\t Capitals\n ") f = open(r'C:\Users\USER\Desktop\Notepad_Read\countries.txt') count = 0 data = f.readlines() for line in data: line = line.rstrip('\n') rec = line.split(',') country = rec[0] capital = rec[1] count = count + 1 print("{0:1}\t{1:26}\t {2:24}".format(count,country,capital)) countries = [] #Empty list capitals = [] #Empty list n = len(countries) ctry = str(input("Enter a country name (x to Exit): ")) i = 0 for line in data: line = line.rstrip('\n') rec = line.split(',') country = rec[0] capital = rec[1] countries.append(rec[0]) #Country are stored in countries list capitals.append(rec[1]) #Capital are stored in capitals list count = count + 1 line = line.rstrip('\n') country, capital = line.split(',') if ctry == 'x': break elif ctry == countries[i]: print ("The capital of {0} is{1}".format(country,capital)) break else: i = i + 1 else: print("{0} is not in the list. Please try again.".format (ctry)) f.close()I had found the solution.
This is what I needed.
Just share to let everyone make references. x)
CASE CLOSED