[Tutor] broken script
Lisi
lisi.reisz at gmail.com
Wed Jul 6 00:01:01 CEST 2011
I am copy-typing the following pre-written program:
def break_words(stuff):
"""This function will break up words for us."""
words=stuff.split(' ')
return words
def sort_words(words):
"""Sorts the words."""
return sorted(words)
def print_first_word(words):
"""Prints the first word after popping it off."""
word=words.pop(0)
print word
I am testing at the end of each section as I type it. As far as line 9 it was
fine - but, once I have typed up to line 14, it jibs at line 10 with the
following error message:
lisi at Tux:~/Python/LearnPythonTheHardWay$ python ex26.py
File "ex26.py", line 10
def print_first_word(words)
^
SyntaxError: invalid syntax
lisi at Tux:~/Python/LearnPythonTheHardWay$
(The caret should be under the closing bracket at the end of the line in which
it is the penultimate character.) I have deleted and re-copy-typed the end
of the line repeatedly. In despair, I deleted the end of the line and copied
and pasted the end of line 6 into it. I have checked and rechecked for
incorrect white-space. I can find nothing wrong. I have copy-pasted it into
a WP just to make the non-printing characters visible. I can still see
nothing wrong. Why is line 6 fine and line 10 a disaster? I can see no
difference in the syntax, though there must clearly be one. :-(
I am at a loss as to what to do next. (It is the next exercise that is
supposed to have errors in for us to put right!!!)
Pointers in the right direction very gratefully received!
Thanks,
Lisi
More information about the Tutor
mailing list