-1

This is for Python 2:

import re

print sum([int(i) for i in re.findall('[0-9]+',open(raw_input('What is the file you want to analyze?\n'),'r').read())])

But why do I get a syntax error with Python 3?

Python3

import re

print sum([int(i) for i in re.findall('[0-9]+',open(input('What is the file you want to analyze?\n')).read())])
Thierry Lathuille
  • 23,663
  • 10
  • 44
  • 50
Shivam Namdeo
  • 11
  • 2
  • 8

1 Answers1

0

That is because in Python3 you should use brackets around the argument for the print function.

print()

so your code will work as soon as you write

print(sum([int(i) for i in re.findall('[0-9]+',open(input('What is the file you want to analyze?\n')).read())]))