Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text01 finished #109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 01-hello.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# 题目: 输入名字,输出 "Hello, 名字"

print "请输入你的名字,然后按 Enter: "
print '请输入你的名字,然后按 Enter: '
your_name = gets

# ...

puts "(请替换成最后的答案)"
print 'Hello,', your_name
4 changes: 3 additions & 1 deletion 02-variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
puts "b 是 #{b}"

# ...
c = b
b = a
a = c

puts "a 应该是 2,现在是 #{a}"
puts "b 应该是 1,现在是 #{b}"

8 changes: 4 additions & 4 deletions 03-triangle.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# 题目: 使用者输入直角三角形的宽和高,输出三角形的面积

print "请输入直角三角形的高,然后按 Enter: "
print '请输入直角三角形的高,然后按 Enter: '
a = gets

print "请输入直角三角形的底边,然后按 Enter: "
print '请输入直角三角形的底边,然后按 Enter: '
b = gets

# .....

puts "直角三角形的面积是: _________"
c = a.to_i * b.to_i / 2
puts "直角三角形的面积是: ____#{c}_____"
10 changes: 6 additions & 4 deletions 04-pizzas.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# 题目: 输入有多少片比萨饼和多少人,输出每人可以分到几片,以及剩下几片

print "请输入有多少片比萨饼,然后按 Enter: "
print '请输入有多少片比萨饼,然后按 Enter: '
pizzas = gets

print "请输入有多少人要吃,然后按 Enter: "
print '请输入有多少人要吃,然后按 Enter: '
people = gets

# .....
a = pizzas.to_i / people.to_i
b = pizzas.to_i % people.to_i

puts "每人可分得几片: _________ 片"
puts "还剩下几片: _________ 片"
puts "每人可分得几片: _____#{a}____ 片"
puts "还剩下几片: ____#{b}_____ 片"
17 changes: 13 additions & 4 deletions 05-bmi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@
# 如果 BMI >= 24,显示过重
# 如果 BMI 介于 18.5 ~ 24,显示正常

print "请输入您的体重(公斤),然后按 Enter: "
print '请输入您的体重(公斤),然后按 Enter: '
weight = gets

print "请输入您的身高(厘米),然后按 Enter: "
print '请输入您的身高(厘米),然后按 Enter: '
height = gets

# .....

puts "您的 BMI 是: _________"
bmi = (weight.to_f / (height.to_f / 100 * height.to_f / 100)).round(2)
a = if bmi < 18.5
'过轻'
elsif bmi >= 24
'过重'
else
'正常'
end

puts "您的 BMI 结果是: _________(过轻或正常或过重)"
puts "您的 BMI 是: ____#{bmi}_____"

puts "您的 BMI 结果是: ___#{a}______(过轻或正常或过重)"
21 changes: 17 additions & 4 deletions 06-interger-positive.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
# 题目: 输入一个数字 x,请判断是否正数、零或负数,以及是不是偶数


print "请输入一个整数,然后按 Enter: "
print '请输入一个整数,然后按 Enter: '
x = gets
a = if x.to_i > 0
'正数'

elsif x.to_i == 0
'零'
else
'负数'
end

c = x.to_i % 2
b = if c == 0
'偶数'
else
'奇数'
end
# ....

puts "这个数是_____ (正数或零或负数)"
puts "这个数是_____ (偶数或奇数)"
puts "这个数是__#{a}___ (正数或零或负数)"
puts "这个数是___#{b}__ (偶数或奇数)"
25 changes: 21 additions & 4 deletions 07-abcde.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,32 @@
# 当 z > 0 输出 "D"
# 当 z < 0 输出 "E"

print "请输入一个整数x,然后按 Enter: "
print '请输入一个整数x,然后按 Enter: '
x = gets

print "请输入一个整数y,然后按 Enter: "
print '请输入一个整数y,然后按 Enter: '
y = gets

print "请输入一个整数z,然后按 Enter: "
print '请输入一个整数z,然后按 Enter: '
z = gets

a = if x.to_i < 0
'A'
elsif x.to_i > 0
if y.to_i > 0
if z.to_i > 0
'B'
elsif
'C'
end
elsif y.to_i < 0
if z.to_i > 0
'D'
elsif z.to_i < 0
'E'
end
end
end
# ....

puts "结果是________(A或B或C或D或E)"
puts "结果是___#{a}_____(A或B或C或D或E)"
16 changes: 12 additions & 4 deletions 08-find-max.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# 题目: 使用者输入 x,y,z,请输出三个数中最大的数

print "请输入一个数字x,然后按 Enter: "
print '请输入一个数字x,然后按 Enter: '
x = gets

print "请输入一个数字y,然后按 Enter: "
print '请输入一个数字y,然后按 Enter: '
y = gets

print "请输入一个数字z,然后按 Enter: "
print '请输入一个数字z,然后按 Enter: '
z = gets

# ....

puts "最大的数是 ________(x或y或z)"
a = if x.to_i >= y.to_i && x.to_i >= z.to_i
x
elsif x.to_i >= y.to_i && x.to_i < z.to_i
z
else
y
end

puts "最大的数是 __#{a}__(x或y或z)"