bash:意外标记‘ex25’附近有语法错误

bash:意外标记‘ex25’附近有语法错误

全部

我曾尝试按照“艰难学习 Python”的步骤编写一个程序。这是练习 25。在额外学分中,它告诉我去做help(ex25),但是当我输入该内容时,我在 linux mint 15 终端上得到了这个:

bash: syntax error near unexpected token `ex25'

请帮忙。这是我的编码:

def break_words(stuff):
    """this function will break-up words for us"""
    words = stuff.split(' ')
    return words

def sort_words(words):
    """sort the words"""
    return sorted(words)

def prints_first_word(words):
    """prints the first word after popping it"""
    word = words.pop (0)
    print word

def print_last_word(words):
    """prints the last word after popping it off"""
    word = words.pop(-1)
    print word

def sort_sentence(sentence):
    """takes in a whole sentence and sorts it"""
    words = break_words(sentence)
    return sort_words(words)

def print_first_and_last(sentence):
    """prints the first and last words of the sentence"""
    words = break_words(sentence)
    prints_first_word(words)
    print_last_word(words)

def print_first_and_last_sorted(sentence):
    """first sorts the words, then prints them"""
    words = sort_sentence(sentence)
    prints_first_word(words)
    print_last_word(words)

答案1

我快速阅读了该示例http://learnpythonthehardway.org/book/ex25.html从你的帖子来看,听起来你是help(ex25)在 bash 提示符下输入,而你应该在完成第一步后在 python 解释器中输入该内容import ex25

相关内容