【发布时间】:2013-12-24 05:02:09
【问题描述】:
我正在尝试“99 瓶”计划。我试图简化它,但我得到“字符串不能被强制转换为 Fixnum”:
num_at_start = 99
num_now = num_at_start
bobo = " bottles of beer on the wall"
bob = " bottles of beer!"
while num_now > 2
puts num_now.to_s + bobo.to_s
puts num_now.to_s + bob.to_s
puts num_at_start.to_i - 1 + bobo.to_s
gets
end
【问题讨论】:
-
您需要在循环中的某处实际减少
num_now。否则它会比实际的歌曲更烦人。 -
哪一行返回错误?而且,为什么你使用
gets而不存储结果?