ex26改錯(cuò)

ex26給了一個(gè)代碼鏈接任務(wù)就是把這個(gè)代碼修改正確,也是很簡(jiǎn)單,把改后的代碼貼上,心細(xì)點(diǎn)就能很快修改完

#coding=utf

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): #少了冒號(hào)
    """Prints the first word after popping it off."""
    word = words.pop(0) #多了個(gè)'o'
    print word

def print_last_word(words):
    """Prints the last word after popping it off."""
    word = words.pop(-1) #少了括號(hào)
    print word

def sort_sentence(sentence):
    """Takes 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):
    """Sorts the words then prints the first and last one."""
    words = sort_sentence(sentence)
    print_first_word(words)
    print_last_word(words)


print "Let's practice everything."
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'

poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explantion
\n\t\twhere there is none.
"""


print "--------------"
print poem
print "--------------"

five = 10 - 2 + 3 - 5
print "This should be five: %s" % five

def secret_formula(started):
    jelly_beans = started * 500
    jars = jelly_beans / 1000 #除號(hào)錯(cuò)誤
    crates = jars / 100
    return jelly_beans, jars, crates


start_point = 10000
beans, jars, crates = secret_formula(start_point)

print "With a starting point of: %d" % start_point
print "We'd have %d jeans, %d jars, and %d crates." % (beans, jars, crates)

start_point = start_point / 10

print "We can also do that this way:"
print "We'd have %d beans, %d jars, and %d crabapples." % secret_formula(start_point)


sentence = "All god\tthings come to those who weight."

words = break_words(sentence)
sorted_words = sort_words(words)

print_first_word(words)
print_last_word(words)
print_first_word(sorted_words)
print_last_word(sorted_words)
sorted_words = sort_sentence(sentence)
print sorted_words

print_first_and_last(sentence)
print_first_and_last_sorted(sentence)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 178,765評(píng)論 25 709
  • 請(qǐng)輸入正文每天一點(diǎn)感觸 去的時(shí)候很遠(yuǎn),回來時(shí)很快。大概是因?yàn)榉艞壉葓?jiān)持容易吧。
    擁人自擾之閱讀 157評(píng)論 0 0
  • 對(duì)呀,看這里看這里,我們找的就是你! 小編們雖然性格各異,但卻都是熱情善良的孩紙呢~如果你也是年輕怕寂寞;幽默怕單...
    7f67504d611e閱讀 422評(píng)論 2 2
  • 前幾天發(fā)小推薦我看《借物少女艾莉緹》,這是一個(gè)關(guān)于遇見-同行-離別的故事,來自不同世界的小人族少女艾莉緹和身患疾病...
    北豆根寫書評(píng)閱讀 545評(píng)論 0 0

友情鏈接更多精彩內(nèi)容