From 9521e2aa55486842d4467cfdcca8b2446ec033b1 Mon Sep 17 00:00:00 2001 From: RealAnalysis Date: Sat, 18 Apr 2020 23:12:10 +0800 Subject: [PATCH 1/7] 01 --- 01-hello.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/01-hello.rb b/01-hello.rb index e0e7bbf..f0e0216 100644 --- a/01-hello.rb +++ b/01-hello.rb @@ -1,8 +1,7 @@ # 题目: 输入名字,输出 "Hello, 名字" print "请输入你的名字,然后按 Enter: " -your_name = gets -# ... +your_name = gets -puts "(请替换成最后的答案)" \ No newline at end of file +puts "Hello, #{your_name}" From 5c4ddfef85b7b49682692bbb2045b7fae2609c9b Mon Sep 17 00:00:00 2001 From: RealAnalysis Date: Sat, 18 Apr 2020 23:54:02 +0800 Subject: [PATCH 2/7] 02 --- 02-variable.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/02-variable.rb b/02-variable.rb index a5a4753..d94a652 100644 --- a/02-variable.rb +++ b/02-variable.rb @@ -6,8 +6,11 @@ puts "a 是 #{a}" puts "b 是 #{b}" -# ... +c = a +a = b +b = c -puts "a 应该是 2,现在是 #{a}" -puts "b 应该是 1,现在是 #{b}" +puts "a \"应该\"是 2,现在是 #{a}" +puts "b \"应该\"是 1,现在是 #{b}" +# 这才是真正的学习了,什么叫 “ ’=’ 是赋值运算符(assignment operator),是指派右边的值到左边的变量” From 24b6f5431917e4d3c05cac5d080ea07b85ca2bb3 Mon Sep 17 00:00:00 2001 From: RealAnalysis Date: Mon, 20 Apr 2020 22:56:17 +0800 Subject: [PATCH 3/7] 04 --- 03-triangle.rb | 4 ++-- 04-pizzas.rb | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/03-triangle.rb b/03-triangle.rb index fafec03..00e3c5e 100644 --- a/03-triangle.rb +++ b/03-triangle.rb @@ -6,6 +6,6 @@ print "请输入直角三角形的底边,然后按 Enter: " b = gets -# ..... +c = a.to_f * b.to_f / 2 -puts "直角三角形的面积是: _________" \ No newline at end of file +puts "直角三角形的面积是: #{c}" diff --git a/04-pizzas.rb b/04-pizzas.rb index 4c2521f..d2c0cb4 100644 --- a/04-pizzas.rb +++ b/04-pizzas.rb @@ -6,7 +6,8 @@ print "请输入有多少人要吃,然后按 Enter: " people = gets -# ..... +a = pizzas.to_i +b = people.to_i -puts "每人可分得几片: _________ 片" -puts "还剩下几片: _________ 片" \ No newline at end of file +puts "每人可分得几片: #{a/b} 片" +puts "还剩下几片: #{a%b} 片" From d2abca52ce5992cb8e189f2382a104d1148e132c Mon Sep 17 00:00:00 2001 From: RealAnalysis Date: Sun, 26 Apr 2020 17:22:10 +0800 Subject: [PATCH 4/7] 05 --- 05-bmi.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/05-bmi.rb b/05-bmi.rb index 67efdff..51be6c8 100644 --- a/05-bmi.rb +++ b/05-bmi.rb @@ -10,8 +10,18 @@ print "请输入您的身高(厘米),然后按 Enter: " height = gets -# ..... +b = height.to_f/100 -puts "您的 BMI 是: _________" +a = weight.to_f/(b * b) -puts "您的 BMI 结果是: _________(过轻或正常或过重)" \ No newline at end of file +if a < 18.5 + c = "过轻" +elsif a >= 24 + c = "过重" +else + c = "正常" +end + +puts "您的 BMI 是: #{a}" + +puts "您的 BMI 结果是: #{c}" From a1f3d0ba0dffd9d939219a3741f9af984b038d7f Mon Sep 17 00:00:00 2001 From: RealAnalysis Date: Sun, 26 Apr 2020 17:31:09 +0800 Subject: [PATCH 5/7] 06 --- 06-interger-positive.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/06-interger-positive.rb b/06-interger-positive.rb index a240f5f..c6ad3d6 100644 --- a/06-interger-positive.rb +++ b/06-interger-positive.rb @@ -4,7 +4,19 @@ print "请输入一个整数,然后按 Enter: " x = gets -# .... +if x.to_i > 0 + a = "正数" +elsif x.to_i < 0 + a = "负数" +else + a = "零" +end -puts "这个数是_____ (正数或零或负数)" -puts "这个数是_____ (偶数或奇数)" \ No newline at end of file +if x.to_i % 2 == 0 + b = "偶数" +else + b = "奇数" +end + +puts "这个数是#{a}" +puts "这个数是#{b}" From 1ed641d585cadc1372cae65e1516e18fcb319038 Mon Sep 17 00:00:00 2001 From: RealAnalysis Date: Sun, 26 Apr 2020 17:48:38 +0800 Subject: [PATCH 6/7] 07 --- 07-abcde.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/07-abcde.rb b/07-abcde.rb index 5d0c8c3..d16ac81 100644 --- a/07-abcde.rb +++ b/07-abcde.rb @@ -17,6 +17,22 @@ print "请输入一个整数z,然后按 Enter: " z = gets -# .... +if x.to_i < 0 + a = "A" +else + if y.to_i > 0 + if z.to_i > 0 + a = "B" + else + a = "C" + end + else + if z.to_i >0 + a = "D" + else + a = "E" + end + end +end -puts "结果是________(A或B或C或D或E)" \ No newline at end of file +puts "结果是#{a}" From 870eadd3a2a26a6a121fcaf573a53c84a5528435 Mon Sep 17 00:00:00 2001 From: RealAnalysis Date: Sun, 26 Apr 2020 22:16:22 +0800 Subject: [PATCH 7/7] 08 --- 08-find-max.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/08-find-max.rb b/08-find-max.rb index 9e6e643..42bb2b3 100644 --- a/08-find-max.rb +++ b/08-find-max.rb @@ -9,6 +9,18 @@ print "请输入一个数字z,然后按 Enter: " z = gets -# .... +if x > y + if x > z + c = "x" + else + c = "z" + end +else + if y > z + c = "y" + else y < z + c = "z" + end +end -puts "最大的数是 ________(x或y或z)" \ No newline at end of file +puts "最大的数是 #{c}"