Exercise 24: More Practice
puts "Let's practice everything."
puts 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.' # the <<END is a "heredoc". See the Student Questions.
poem = <<END
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\twhere there is none.
END puts "--------------"
puts poem
puts "--------------" five = 10 - 2 + 3 - 6
puts "This should be five: #{five}" def secret_formula(started)
jelly_beans = started * 500
jars = jelly_beans / 1000
crates = jars / 100
return jelly_beans, jars, crates
end start_point = 10000
beans, jars, crates = secret_formula(start_point) puts "With a starting point of: #{start_point}"
puts "We'd have #{beans} beans, #{jars} jars, and #{crates} crates." start_point = start_point / 10
puts "We can also do that this way:"
puts "We'd have %s beans, %d jars, and %d crates." % secret_formula(start_point)
""与<<XXX的写法,\t会变成空格,\n会换行
''里面是什么就是什么
Let's practice everything.
You'd need to know 'bout escapes with \ that do \n newlines and \t tabs.
--------------
The lovely world
with logic so firmly planted
cannot discern
the needs of love
nor comprehend passion from intuition
and requires an explanation where there is none.
--------------
This should be five: 5
With a starting point of: 10000
We'd have 5000000 beans, 5000 jars, and 50 crates.
We can also do that this way:
We'd have 500000 beans, 500 jars, and 5 crates.
Exercise 24: More Practice的更多相关文章
- 【Bell-Ford 算法】CLRS Exercise 24.1-4,24.1-6
本文是一篇笔记,大部分内容取自 CLRS 第三版,第 24.1 节. Exercise 24.1-4 Modify the Bellman-Ford algorithm so that it sets ...
- Simple Tips for Collection in Python
I believe that the following Python code is really not hard to understand. But I think we should use ...
- 【239】◀▶IEW-Unit04
Unit 4 Youth Issues: Computer Use 1 Model1题目及范文分析 Some teenagers spend a lot of time playing compute ...
- Building Applications with Force.com and VisualForce(Dev401)(十一):Designing Applications for Multiple Users: Proseving Data Quality
Dev401-012:Proseving Data Quality Universal Containers Scenario1.Universal Containers(UC) wants to e ...
- Matlab解析LQR与MPC的关系
mathworks社区中的这个资料还是值得一说的. 1 openExample('mpc/mpccustomqp') 我们从几个角度来解析两者关系,简单的说就是MPC是带了约束的LQR. 在陈虹模型预 ...
- CMSC 216 Exercise #5
CMSC 216 Exercise #5 Spring 2019Shell Jr (”Shellito”) Due: Tue Apr 23, 2019, 11:30PM1 ObjectivesTo p ...
- MIT 6.828 JOS学习笔记5. Exercise 1.3
Lab 1 Exercise 3 设置一个断点在地址0x7c00处,这是boot sector被加载的位置.然后让程序继续运行直到这个断点.跟踪/boot/boot.S文件的每一条指令,同时使用boo ...
- OpenJudge 2787 算24
1.链接地址: http://poj.org/problem?id=1631 http://bailian.openjudge.cn/practice/2787/ 2.题目: 总时间限制: 3000m ...
- JavaSE学习总结第24天_多线程2
24.01 JDK5之后的Lock锁的概述和使用 虽然我们可以理解同步代码块和同步方法的锁对象问题,但是我们并没有直接看到在哪里加上了锁,在哪里释放了锁,为了更清晰的表达如何加锁和释放锁,JDK ...
随机推荐
- 通过JS检测360浏览器
如何通过JS检测360浏览器? 尝试了一大堆方法,网上大多数办法都是通过navigator.userAgent来判断,这可能在几年前是行得通的,现在360userAgent输出来跟谷歌除了版本号其余一 ...
- spark2.0.1 安装配置
1. 官网下载 wget http://d3kbcqa49mib13.cloudfront.net/spark-2.0.1-bin-hadoop2.7.tgz 2. 解压 tar -zxvf spar ...
- shell 转义字符的写法
在链接中,往往会遇到含有‘&'字符的情形,需要转义方能使用. 以下是它的写法样例,错误的写法勿要再犯!! 链接样例: http://my.example.cn/show/details/htd ...
- PHP正则表达式替换站点关键字链接后空白的问题解决
标题这样不知道合适不合适.具体的情况是这样的:网站要增加关键字链接功能,然后需要对文章的内容进行正则表达式匹配并替换,然后使用了preg_replace函数.替换的程序代码如下: function R ...
- Windows Server 2012 中80端口被PID为4的系统进程占用解决方法
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP 把"start" 的值改成4.
- 移动端flex布局 微信和UC的兼容性
请查看以下两个链接 http://www.tuicool.com/articles/Afq6Bzq http://www.sheng00.com/2148.html
- 在 Xcode 7 中安装 Alcatraz
http://www.jianshu.com/p/5c8ed25ad434 安装Xcode7后,继续采用官方方法安装Alcatraz,发现不成功.单独安装XVim也不成功.看了一下Alcatraz的i ...
- hihoCoder#1000
刚开始学习C语言,准备在做hiho的题目的过程中来学习,在此进行记录,如果代码中有错误或者不当的地方还请指正. 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 求两个整 ...
- AngularJS身份验证:Cookies VS Tokens
基于cookie的身份验证:Cookie-Based Authentication 基于token的身份验证:Token-Based Authentication 跨域:cross-domain 说明 ...
- c# 第一个实例 通哥
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...