I want to read a file line by line. These lines contain operators and numbers. If it's a "+" i will add the number that follows, it it's a "-" i will subtract the number that follows. This will be kept in a count variable. This count variable will then be stored in a list. I will continue to loop through the file until a duplicate count value is found. My idea is to continue to loop until i find a duplicate (hence my while condition). But when I get to the end of the file i need to start over!! So the count at the end of the file will now start from the beginning
While loop and then a for loop
def computeProblemOnePointFive(inputFileString):
inputFile = open(inputFileString, "r")
count = 0
countsList=[]
while len(countsList) == len(set(countsList)):
for line in inputFile:
if "+" in line:
value = int(line.strip("+"))
count = count + value
countsList.append(count)
if "-" in line:
value = int(line.strip("-"))
count = count - value
countsList.append(count)
return countsList[-1]