0

我对这个 Lua 代码做错了什么?我正在尝试生成两个随机数并询问它们相乘的内容。第一部分很好,但无论我输入什么作为答案,它总是认为它是不正确的。请告诉我我做错了什么以及如何解决它。记住这是 Lua。

math.randomseed(os.time())
local a=math.random(10)
local b=math.random(10)


local answer
repeat
io.write("What is ",a,"*",b,"?")    
io.flush()  
answer=io.read()
if answer==a*b then
print("Correct!")
else
print("Try Again")
end
until
answer==a*b
4

1 回答 1

4

io.read()返回 a string,并且您将它与数字进行比较。

你要么需要说answer=tonumber(io.read()),要么你需要说io.read("*n")

于 2013-03-15T21:56:19.767 回答