我是学ruby的新手,我想知道为什么当我输入150时,它并没有说你是完美的这是我正在处理的代码。

 def prompt
   print ">> "
 end

 puts "welcome to the weight-calc 3000! Enter you weight below!"

 prompt; weight = Integer(gets.chomp())

 if weight > 100 && weight < 300
   puts "your healthy!"
 elsif weight > 300
   puts "your fat"
 elsif weight < 100
   puts "your skinny"
 elsif weight == 150
   puts "your perfect"
 end

最佳答案

if weight > 100 && weight < 300的条件是true,因此最后一个150甚至没有输入。
你应该把更具体的条件(elsif)放在一般条件(weight == 150)之前。

10-01 07:14
查看更多