2017-10-13 30 views
-6

我需要帮助,因为这没有奏效。 它给出了一个错误消息:来自CodeAcademy的红宝石控制流量在RUBY敢于比较

(红宝石):8:语法错误,意想不到的结束输入,期望 ')'

确保把一个表达中每个=!之后。 运行:

(#) test_1 should be false 
test_1 = 10 < 8 

(#) test_2 = should be false 
test_2 = 8 > 10 

(#) test_3 = should be true 
test_3 = 8 != 8 
+2

你应该输入的内容只是“应该是错误的”之后的部分,例如你只需输入'test1 = 10 <8' –

+0

我只是尝试,仍然无法正常工作。 (红宝石):8:语法错误,意外的输入结束,期待')' –

+0

你只是要确保是否给出的以下陈述是真或假 –

回答

0

是什么(#)意思?

就启动了一个parenthesised表达((一切都在Ruby是一个表达式),然后有一个评论#) test_1 should be false,然后表达test_1 = 10 < 8,则内parenthesised表达(,然后评论#) test_2 = should be false,等,等,但也有没有右括号,因此错误。

这工作:

(#) test_1 should be false 
test_1 = 10 < 8 

(#) test_2 = should be false 
test_2 = 8 > 10 

(#) test_3 = should be true 
test_3 = 8 != 8 
))) 

执行:

$ ruby -w t_op.rb 
t_op.rb:2: warning: assigned but unused variable - test_1 
t_op.rb:5: warning: assigned but unused variable - test_2 
t_op.rb:8: warning: assigned but unused variable - test_3 

其实你想要做的是:

# test_1 should be false 
test_1 = 10 < 8 

# test_2 = should be false 
test_2 = 8 > 10 

# test_3 = should be true ???? 
test_3 = 8 != 8 

# test_4 = should be true 
test_4 = 8 != 18 

puts "test_1=#{test_1.inspect}" 
puts "test_2=#{test_2.inspect}" 
puts "test_3=#{test_3.inspect}" 
puts "test_4=#{test_4.inspect}" 

执行:

$ ruby -w t.rb 
test_1=false 
test_2=false 
test_3=false 
test_4=true