-5
我在做第11个练习了解Ruby的难法。我一定要得到这样的:通过写这Gets.chomp不能正常工作
How old are you? 35
How tall are you? 6'2"
How much do you weigh? 180lbs
So, you're 35 old, 6'2" tall and 180lbs heavy.
:
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."
,但我得到这个:
How old are you?
How tall are you?
How much do you weigh?
So, you're old, tall and heavy.
这意味着,gets.chomp
不工作,我不明白任何东西。
方法'gets.chomp()'在哪里?这似乎要么没有返回,要么可能是其他问题......? – gravity
@gravity'Kernel#gets'和'String#chomp'是Ruby核心方法。 –
@MladenJablanović这是我的观点:) – gravity