如何输出Lua计算结果

-- 将cl赋值为随机的加号或减号
Local cl = rendom - or +
-- 将a赋值为随机数
Local a  = rendom number
-- 将x赋值为随机数
Local x  = rendom number
-- 将re拼接为'a cl x'的字符串
Locol re = a..cl..x
-- 输出re,例如输出'5+8'
Print (re)

我需要得到结果13

如何实现?

点赞
用户870125
用户870125

如果您想获得数字13,可以尝试:

Local cl = rendom "m" or "p" -- m代表减法,p代表加法
Local a  = rendom number
Local x  = rendom number
Local re = 0
if cl == "m" then re = a-x end
if cl == "p" then re = a+x end
Print (re) --输出13

或者

Local cl = rendom "m" or "p" -- m代表减法,p代表加法
Local a  = rendom number
Local x  = rendom number
Local re = 0
if cl == "m" then re = a-x Print(a.."-"..x, re) end
if cl == "p" then re = a+x Print(a.."+"..x, re) end

希望这有所帮助!

2020-02-24 16:48:07