markdown 公共要点 - 图灵 - 预备工作第5天完成的项目汇编

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 公共要点 - 图灵 - 预备工作第5天完成的项目汇编相关的知识,希望对你有一定的参考价值。

Exercise #1
In your prework gist, answer the following questions regarding the string, “Turing”. What ruby command would we use to get:

1. The “T” from “Turing”.
"Turing"[0]

2. The length of “Turing”.
"Turing".length
 
3. Make the whole string capital letters.
"Turing".upcase
 
4. Delete the “n” from “Turing”.
"Turing".delete("n")
 
5. Assign “Turing” to a variable.
turing = "Turing"

Exercise #2
In your prework gist, answer the following questions:

1. What does gets do?
A method, gets, retrives the user's response in a string format.

2. What is the difference between the input without the .chomp and the input with the .chomp?
will strip your text of any newlines, or carrige returns at the end
Input without .chomp returns the new line created when the user enters a value and presses return.  Input with .chomp strips out any new lines created, including carriage returns, when the user enters a value and presses return.

3. What does fav_num.to_i do?
The method, to_i, converts fav_num's string to an integer.

Exercise #3
In your prework gist, answer the following questions:
1. What does animals.length return?
4

2. What does animals[0] return?
dog

3. What does animals.empty? return?
false

4. What are two different ruby commands that add to the animals?
push and <<

Example:  
2.5.0 :007 > animals.push("bird")
 => ["dog", "cat", "penguin", "armadillo", "bird"] 
2.5.0 :008 > animals << "crocodile"
 => ["dog", "cat", "penguin", "armadillo", "bird", "crocodile"] 
 
Use insert to multiple values at one time.

5. What ruby command is used to remove the last element from the array?
pop

Example:
2.5.0 :009 > animals.pop
 => "crocodile" 
2.5.0 :010 > animals
 => ["dog", "cat", "penguin", "armadillo", "bird"] 
2.5.0 :011 > 

以上是关于markdown 公共要点 - 图灵 - 预备工作第5天完成的项目汇编的主要内容,如果未能解决你的问题,请参考以下文章

markdown 公共要点 - 图灵 - 预备工作第4天完成的项目汇编

markdown 公共要点 - 图灵 - 预备工作第3天完成的项目汇编

markdown 公共要点 - 图灵 - 预备工作第2天完成的项目汇编

markdown 公共要点 - 图灵 - 预备工作第1天完成的项目汇编

markdown 公共要点 - 图灵 - 完成装备要点的项目汇编

markdown 公共要点 - 图灵 - 完成专业发展的项目汇编