小编Col*_*n R的帖子

Ruby中的if语句冲突

我尝试在支持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)

关于如何解决这个问题的任何想法?

ruby ide if-statement puts ruby-1.8.7

1
推荐指数
2
解决办法
253
查看次数

标签 统计

ide ×1

if-statement ×1

puts ×1

ruby ×1

ruby-1.8.7 ×1