我正在尝试使用一个随机数来确定事件是否会通过if语句发生。
我一直收到以下错误:
lunarlander.rb:13: syntax error, unexpected '='
if (numb % = 2)*代码如下:
def space_travel
puts "\n"
puts "You engage the main thrusters and you feel the ship jerk forward."
numb = rand(10)
if (numb % == 2)
puts "Everything functions as expected. You settle in for the trip."
else
spacewalk()
end
end发布于 2019-12-20 03:50:19
您需要模运算符(%)的第二个参数。现在你有了
numb % == 2你需要在模数和等于数之间插入一个数字(或一个数值变量),例如
numb % 5 == 2https://stackoverflow.com/questions/59416050
复制相似问题