gpt4 book ai didi

lua - 尝试将数字与字符串进行比较(Lua)

转载 作者:行者123 更新时间:2023-12-05 09:26:41 36 4
gpt4 key购买 nike

我一直在编程

io.write("How many languages do you speak?\n")

answer = io.read()

if (answer == 1)
then
io.write("You're a monolingual beta")
elseif (answer == 2)
then
io.write("You're bilingual")
elseif (answer == 3)
then
io.write("You're a multilingual semichad")
elseif (answer == 4)
then
io.write("You're a polyglot")
elseif (answer == 5)
then
io.write("You're a super polyglot")
elseif (answer == 6)
then
io.write("You're an hyper polyglot")
elseif (answer == 7)
then
io.write("You're a ultra polyglot")
elseif (answer == 8)
then
io.write("You're a mega polyglot")
elseif (answer == 9)
then
io.write("You're an ultra-mega polyglot")
elseif (answer >= 10)
then
io.write("You're an infinite polyglot gigachad")
end

但是当我尝试执行它并输入一个数字时,它只是在标题中显示错误。报错的代码行就是这一行

elseif (answer >= 10)

我真的无法理解这个问题。没有字符串。有人可以帮帮我吗?

最佳答案

answer 变量包含一个字符串作为 io.read() 调用的结果。在 io.read() 周围添加 tonumber 或使用 io.read("n") 获取数字。

关于lua - 尝试将数字与字符串进行比较(Lua),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73532887/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com