题目中给出的代码如下:

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.poop(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 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
#这里\应该为/,在一般情况下\代表转移。
crates = jars / 100
return jelly_beans, jars, crates start_point = 10000
beans, jars, crates == secret_formula(start-point)
#这里面函数变量写错了,应该为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_pont
#这一样少了一个括号。 sentence = "All god\tthings come to those who weight." words = ex25.break_words(sentence)
sorted_words = ex25.sort_words(words)
#本练习中没引进ex25,所有有两种修改方法import ex25,我选用的是去掉ex25.
print_first_word(words) print_last_word(words) .print_first_word(sorted_words)
#本行多了一个.
print_last_word(sorted_words)
sorted_words = ex25.sort_sentence(sentence)
#本练习中没引进ex25,所有有两种修改方法import ex25,我选用的是去掉ex25.
prin sorted_words
#上面的关键字print错误
print_irst_and_last(sentence) print_first_a_last_sorted(senence)
#上面一行缩进存在问题

修正后

#!/usr/bin/env python
# -*- coding:utf-8 -*- def break_words(stuff):
"""This function will break up words for us."""
b_words = stuff.split(' ')
return b_words def sort_words(s_words):
"""Sorts the words."""
return sorted(s_words) def print_first_word(pf_words):
"""Prints the first word after popping it off."""
pf_word = pf_words.pop(0)
print pf_word def print_last_word(pl_words):
"""Prints the last word after popping it off."""
pl_word = pl_words.pop(-1)
print pl_word def sort_sentence(in_sentence):
"""Takes in a full sentence and returns the sorted words."""
out_words = break_words(in_sentence)
return sort_words(out_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(pf_sentence):
"""Sorts the words then prints the first and last one."""
pf_words = sort_sentence(pf_sentence)
print_first_word(pf_words)
print_last_word(pf_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(d_started):
d_jelly_beans = d_started * 500
d_jars = d_jelly_beans / 1000
d_crates = d_jars / 100
return d_jelly_beans, d_jars, d_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 /= 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)

ex26 纠正练习的更多相关文章

  1. C#图片色彩的纠正-上

    WPF(C#)图片色彩的纠正-上 WPF(C#)图片色彩的纠正-下 前言 对图片进行色彩的纠正,其实与WPF是没有什么关系的,为什么标题又是“WPF(C#)图片色彩的纠正”呢,因为这些图片色彩的纠正功 ...

  2. 对属性NaN的理解纠正和对Number.isNaN() 、isNaN()方法的辨析

    1.属性NaN的误解纠正 NaN (Not a Number)在w3c 中定义的是非数字的特殊值 ,它的对象是Number ,所以并不是任何非数字类型的值都会等于NaN,只有在算术运算或数据类型转换出 ...

  3. CSS下拉列表错误纠正

    上一篇关于CSS制作下来列表的错误纠正. 在上一篇中,用CSS只做了下拉列表,但是鼠标不放在导航栏上的时候,下拉列表也是出来的.具体错误就是 div ul{ list-style:none; max- ...

  4. C# winform 若要在加载设计器前避免可能发生的数据丢失,必须纠正以下错误

    winform中有时添加了新控件之后编译会报错: 若要在加载设计器前避免可能发生的数据丢失,必须纠正以下错误,如图: 解决方案: 1.“解决方案”→“批生成”→“清理”→“确定”: 2.“解决方案”→ ...

  5. JAVA classpath, 纠正我一直以来错误的认知

    如何调在CLI中使用java tool(JDK中的java命令)调用一个打包在jar中的类,我想大多数人都能给出笼统的方案: java -classpath xxxxx com.test.classA ...

  6. VS2008 由于应用程序配置不正确,应用程序未能启动。重新安装应用程序可能会纠正这个问题。

    提示这个错误,自己的程序是在VS2008下编译的C/C++ win32程序,自己当时在win7上开发测试,都没有问题,正常使用,也在另一台xp系统上也试了,都没有问题.就发给客户了,没想到有些客户竟然 ...

  7. 关闭 Mac 拼写自动纠正与横线转换

    如果你是个程序员, 如果你恰好用 mac 自带的 notes 来做笔记, 很大可能性, 你会在里面贴代码, 但是, Mac 的拼写检查和自动纠正功能,会把代码变成你不想要的样子, 比如, 它会为你首字 ...

  8. 命令纠正工具 thefuck 的简单使用

    在unix系列的系统中,总会出现 命令拼写或者执行错误的情况, 比如 把 python 写成了pythou, cd 到一个不存在的目录,执行任务的权限 不够的问题, 这是心里 总是 在 fuck,但是 ...

  9. java 英文单词拼写纠正框架(Word Checker)

    Word Checker 本项目用于单词拼写检查. 项目简介 word checker 用于单词拼写检查. Github 地址 特性说明 支持 i18n 错误提示支持 i18N 支持英文的单词纠错 可 ...

随机推荐

  1. C++string中用于查找的find系列函数浅析

    总述:      以下所讲的所有的string查找函数,都有唯一的返回类型,那就是size_type,即一个无符号整数(按打印出来的算).若查找成功,返回按查找规则找到的第一个字符或子串的位置:若查找 ...

  2. 【Unity】常用代码

    //父子节点相关的: parent 变量表示Transform的父节点 root 表示它的根节点,如果没有父节点,它会返回自己 //根据名字查找子节点 Transform Find(string na ...

  3. centos7 docker mysql56

    yum -y install docker docker pull centos docker run --name=mysqltmp -i -t centos /bin/bash yum -y in ...

  4. LTE Module User Documentation(翻译11)——配置用户测量

    LTE用户文档 (如有不当的地方,欢迎指正!) 17 Configure UE measurements   仿真中激活的用户测量配置取决于所选的 “consumers”,例如切换算法.用户可能需要添 ...

  5. LTE Module User Documentation(翻译10)——网络连接(Network Attachment)

    LTE用户文档 (如有不当的地方,欢迎指正!) 16 Network Attachment(网络连接)   正如前面章节 Basic simulation program 所述,连接用户到基站时通过调 ...

  6. Shell脚本查看apk签名信息

    用shell写了一个查看apk签名的脚本.代码很少也很简单 支持递归目录查询 #!/bin/bash #使用方法 ./getcertificate.sh xx.apk get_signature() ...

  7. Shell 语法之结构化命令(流程控制)

    许多程序在脚本命令之间需要某种逻辑流控制,允许脚本根据变量值的条件或者其他命令的结果路过一些命令或者循环执行这些命令.这些命令通常被称为结构化命令.和其他高级程序设计语言一样,shell提供了用来控制 ...

  8. Ubuntu中设置静态IP和DNS

    在Ubuntu中设置静态IP共两步:1>设置IP:2>设置DNS1>设置IP    编辑 /etc/network/interface文件:       sudo vi /etc/n ...

  9. 详解应对平台高并发的分布式调度框架TBSchedule

    转载: 详解应对平台高并发的分布式调度框架TBSchedule

  10. java.util.concurrent包分类结构图

    摘自:http://blog.csdn.net/tsyj810883979/article/details/6956290