The problem is that you're using input
. In Python 2, input
asks for input, and then tries to evaluate it as Python code.
So, when you type in 8 9 3 2 7 5
, it tries to evaluate that as Python code—and of course that's not valid Python syntax.
What you want to do is use raw_input
, which just asks for input and returns it to your code as a string. You can then call split()
on it and get a list of strings.
When you move to Python 3, this problem goes away—input
just returns a string.
Meanwhile, just putting the result of split()
in brackets doesn't do much good. You end up with a list, whose one element is another list, whose elements are the split strings. So you probably just want:
A = raw_input().split()
If you need to convert each string into an int, you have to call int
on each one. You can do this with a list comprehension:
A = [int(numeral) for numeral in raw_input().split()]
… or map
:
A = map(int, raw_input().split())
… or an explicit loop:
A = []
for numeral in raw_input().split():
A.append(int(numeral))
If you don't understand the first two, use the last one until you can figure out how they work. Concise, readable code is very important, but code that you can understand (and debug and maintain and extend) is even more important.