我正在尝试使用随机数来确定事件是否会通过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
答案 0 :(得分:2)
您需要模运算符(x = b'S\xa0S\xa0\xa0\xa0\xa0\xa0\xa0\xb23.6\xb7\xa0\xe7\x8d\n'
x.decode('utf-8', errors='ignore')
>>> 'SS3.6\n'
)的第二个参数。现在你有
\xb
,您需要在模和等号之间插入数字(或数字变量)
%