我尝试在支持 Ruby 1.8.7 的在线 IDE 中运行此代码,但elsif
无法识别该语句;例如,如果我输入“85”,它仍然会返回“Over-Weight”。
def prompt
print ">> "
end
puts "Welcome to the Weight-Calc 3000! Enter your weight below!"
prompt; weight = gets.chomp()
if weight > "300"
puts "Over-weight"
elsif weight < "100"
puts "Under-weight"
end
但是,当我运行以下命令时,它工作得很好:
def prompt
print ">> "
end
puts "Welcome to the Weight-Calc 3000! Enter your weight below!"
prompt; weight = gets.chomp()
if weight > "300"
puts "Over-weight"
elsif weight > "100" && weight < "301"
puts "You're good."
end
关于如何解决这个问题的任何想法?