我尝试在支持Ruby 1.8.7的在线IDE中运行此代码,并且该elsif语句未被识别; 例如,如果我输入"85",它仍然会返回"超重".
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
Run Code Online (Sandbox Code Playgroud)
但是,当我运行以下操作时,它可以正常工作:
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
Run Code Online (Sandbox Code Playgroud)
关于如何解决这个问题的任何想法?