[译]LRTHW练习七——更多输出打印

英文版:http://ruby.learncodethehardway.org/book/ 

繁体版:http://lrthw.github.io/

(繁体+英文-》简体)

现在添加一批练习,在练习过程中写代码,并让你的代码运行起来。这里不会有很多详细的解释,因为大部分都是以前的内容。这次练习的目的是为了巩固你学到的东西,后面再添加息内容——不要跳过,不要复制粘贴。

puts "Mary had a little lamb."
puts "Its fleece was white as #{'snow'}."
puts "And everywhere that Mary went."
puts "." * 10  # what'd that do?

end1 = "C"
end2 = "h"
end3 = "e"
end4 = "e"
end5 = "s"
end6 = "e"
end7 = "B"
end8 = "u"
end9 = "r"
end10 = "g"
end11 = "e"
end12 = "r"

# watch that print vs. puts on this line what's it do?
print end1 + end2 + end3 + end4 + end5 + end6
puts end7 + end8 + end9 + end10 + end11 + end12

输出结果:

$ ruby ex7.rb
Mary had a little lamb.
Its fleece was white as snow.
And everywhere that Mary went.
..........
CheeseBurger

课后习题:

后面几节的思考题都是一样的

1、回去阅读你的代码并且在每一行添加注释

2、倒着阅读你的代码,找出你的错误

3、从现在开始,记录你犯的每一个错误,并且说明原因及解决方案

4、当你准备下一次练习的时候,回顾一下你的错误集锦,并且吸取教训,尽量在下一次练习中不要犯相同的错误。

5、记住:是人都会犯错!程序员们就像魔术师一样,让人们觉得他们的表演很完美,但是那一切都是表象,并且他们也时不时会犯些错误。

 

posted @ 2014-09-01 17:16  SchrodingerCat  阅读(189)  评论(0编辑  收藏  举报