在pythonex25.py中获得不同的输出。从hardway.python 3.6学习python
ex25.py 运行输出如下在pythonex25.py中获得不同的输出。从hardway.python 3.6学习python,python,python-3.x,Python,Python 3.x,ex25.py 运行输出如下 def break_words(stuff): """This function will break up words for us .""" words = stuff.split(' ') # words = stuff.split('') prevents from running the program. return words def sort_words(words): """Sorts the words."
def break_words(stuff):
"""This function will break up words for us ."""
words = stuff.split(' ') # words = stuff.split('') prevents from running the program.
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)
def print_last_word(words):
"""Print the last word after popping it off."""
word = words.pop(-1)
print(word)
def sort_sentence(sentence):
"""Take in a full sentence and returns the sorted words."""
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)
print_first_word(words)
print_last_word(words)
def print_first_and_last_sorted(sentence):
"""Sort the words then prints the first and last one."""
words = sort_sentence(sentence)
print_first_word(words)
print_last_word(words)
imported to ex25 session.py
import ex25
sentence = "All good things come to those who waite."
words = ex25.break_words(sentence)# the space in "words = stuff.split('')" stoped the program from running.
words
sorted_words = ex25.sort_words(words)
sorted_words
ex25.print_first_word(words)
ex25.print_first_word(words)
words
ex25.print_first_word(sorted_words)
ex25.print_last_word(sorted_words)
sorted_words
sorted_words = ex25.sort_words(sentence)
sorted_words
ex25.print_first_and_last(sentence)
ex25.print_first_and_last_sorted(sentence)
谁
我试着把代码分解成几个部分。我找到了where(Break和sort函数,程序会跳过它们!)。请注意,我正在使用pycharm python 3.7。您好,您能更详细地说明您尝试运行的内容吗?sort_words(Break_words(句子))工作…我没有收到任何让人如此困惑的错误。例如,我关闭了排序函数并运行程序的其他部分等等。
All
good
All
who
All
waite.
All