I am trying to find the sum of to values from a text file that is equal to 2020 with python. The text file contains multiple numbers each written in one line like this:
What is the easiest and fastest way to do this in python?
My code reads in the file correctly but does not access the inner for loop?
data = []
try:
file = open('/Users/korbinianschleifer/desktop/input.txt', 'r+')
data = file.readlines()
file.close()
except x:
print('file could not be loaded')
print(len(data))
for i in range(len(data)):
for j in range(i+1,len(data)):
if data[i]+data[j] == 2020:
print('solution found')
