title: How to extract all the numbers from a text file using re.findall() and compute the sum using a for-loop?
body: <p>The basic outline of this problem is to read the file, look for integers using the <code>re.findall()</code>, looking for regular expression of <code>[0-9]+</code> and then converting the extracted strings to integers and summing up the integers. I'm having different outcome it supposed to end with (209). Also, how can I simplify my code? Thanks (here is the txt file <a href="http://py4e-data.dr-chuck.net/regex_sum_167791.txt" rel="nofollow noreferrer">http://py4e-data.dr-chuck.net/regex_sum_167791.txt</a>)</p>
  
  <pre><code>import re
  hand = open("regex_sum_167791.txt")
  total = 0
  count = 0
  for line in hand:
     count = count+1
     line = line.rstrip()
     x =  re.findall("[0-9]+", line) 
     if len(x)!= 1 : continue
     num = int(x[0])
     total = num + total
  print(total)
  </code></pre>