From 9521e2aa55486842d4467cfdcca8b2446ec033b1 Mon Sep 17 00:00:00 2001 From: RealAnalysis Date: Sat, 18 Apr 2020 23:12:10 +0800 Subject: [PATCH 01/10] 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 02/10] 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 03/10] 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 04/10] 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 05/10] 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 06/10] 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 07/10] 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}" From 17793832e5e53bfdc66eab7ec058c126b884a47f Mon Sep 17 00:00:00 2001 From: RealAnalysis Date: Mon, 27 Apr 2020 17:25:27 +0800 Subject: [PATCH 08/10] 09 --- 09-function.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/09-function.rb b/09-function.rb index b1f922d..acc468e 100644 --- a/09-function.rb +++ b/09-function.rb @@ -1,7 +1,7 @@ # 题目: 输入直角三角形的宽和高,输出三角形的面积 def calculate_area(a, b) - # .... + a.to_f * b.to_f / 2 end print "请输入直角三角形的高,然后按 Enter: " @@ -12,4 +12,4 @@ def calculate_area(a, b) answer = calculate_area(a,b) -puts "直角三角形的面积是: #{answer}" \ No newline at end of file +puts "直角三角形的面积是: #{answer}" From 5c935c1d23146bca758dfdd7a0d3f0c97d89930b Mon Sep 17 00:00:00 2001 From: RealAnalysis Date: Mon, 27 Apr 2020 18:26:54 +0800 Subject: [PATCH 09/10] modified 08 --- 08-find-max.rb | 8 ++++---- 10-function.rb | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/08-find-max.rb b/08-find-max.rb index 42bb2b3..e80071b 100644 --- a/08-find-max.rb +++ b/08-find-max.rb @@ -9,16 +9,16 @@ print "请输入一个数字z,然后按 Enter: " z = gets -if x > y - if x > z +if x.to_f > y.to_f + if x.to_f > z.to_f c = "x" else c = "z" end else - if y > z + if y.to_f > z.to_f c = "y" - else y < z + else c = "z" end end diff --git a/10-function.rb b/10-function.rb index bb450fb..e677d23 100644 --- a/10-function.rb +++ b/10-function.rb @@ -1,6 +1,19 @@ # 题目: 使用者输入 x,y,z,请输出三个数中最大的数 def find_max(x, y, z) + if x > y + if x > z + c = "x" + else + c = "z" + end + else x < y + if y > z + c = "y" + else y < z + c = "z" + end + end end print "请输入一个数字x,然后按 Enter: " @@ -12,8 +25,7 @@ def find_max(x, y, z) print "请输入一个数字z,然后按 Enter: " z = gets -# .... answer = find_max(x,y,z) -puts "最大的数是 #{answer}" \ No newline at end of file +puts "最大的数是 #{answer}" From b54e770f983f7e6ed73e8b11bac2c550c91867c5 Mon Sep 17 00:00:00 2001 From: RealAnalysis Date: Mon, 27 Apr 2020 18:36:00 +0800 Subject: [PATCH 10/10] 10 --- 10-function.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/10-function.rb b/10-function.rb index e677d23..cb7faf5 100644 --- a/10-function.rb +++ b/10-function.rb @@ -1,16 +1,16 @@ # 题目: 使用者输入 x,y,z,请输出三个数中最大的数 def find_max(x, y, z) - if x > y - if x > z + if x.to_f > y.to_f + if x.to_f > z.to_f c = "x" else c = "z" end - else x < y - if y > z + else + if y.to_f > z.to_f c = "y" - else y < z + else c = "z" end end