0

所以这是我的代码。这是不言自明的。

print "How old are you? "
age = gets.chomp()
print "How tall are you?"
height = gets.chomp()
print "How much do you weigh?"
weight = gets.chomp()
puts "So, you're #{age} old, #{height} tall and #{weight} heavy."

我的代码输出如下。

$  C:/Ruby200/bin/ruby.exe ex11.rb
11
11
11
How old are you? How tall are you?How much do you weigh?So, you're 11 old, 11 tall and 11 heavy.

这可能是一个非常简单的错误,但如果您能指出这一点,我将不胜感激。

4

1 回答 1

1

我认为您的问题是:“在所有输入之后,我的所有提示都会一次打印出来。这是怎么回事?”。那我给你一个答案:)

print不会在字符串中添加换行符。并且 STDOUT 不会刷新,直到它有一条完整的线。简单修复:替换printputs(添加换行符)

puts "How old are you? "
age = gets.chomp()
puts "How tall are you?"
height = gets.chomp()
puts "How much do you weigh?"
weight = gets.chomp()
puts "So, you're #{age} old, #{height} tall and #{weight} heavy."
于 2013-06-26T12:40:55.743 回答