我想在 Lua 4 中使用这个函数:
function ternary(cond, T, F)
if cond then return T else return F end
end
Run Code Online (Sandbox Code Playgroud)
在这种情况下:
loadHW1 = false
print(ternary(loadHW1 == true, "this should not appear", nil))
Run Code Online (Sandbox Code Playgroud)
但是,文本总是在我期望结果为nil. 我究竟做错了什么?谢谢。
[编辑]
我切换到这个,但仍然得到“这是真的”结果:
loadHW1 = 0
print(ternary(loadHW1, "this is true", "this is false"))
Run Code Online (Sandbox Code Playgroud) 我想创建一些 VBA 代码,如下所示:
fndList.Add "Beat 'em up game", "Beat 'em up"
fndList.Add "Bish?jo game", "Bish?jo"
fndList.Add "Bullet hell game", "Bullet hell"
fndList.Add "Business simulation game", "Business sim"
Run Code Online (Sandbox Code Playgroud)
但是,Excel 将第 2 行转换为“Bishojo 游戏”,没有特殊字符。我应该如何处理这些字符?谢谢。
我正在尝试创建一个Python字典数组,其中输入顺序很重要并且数据可能是各种类型。(即字符串、整数、浮点数等)
Lua 中的示例如下所示:
build =
{
{
Type = SubSystem,
ThingToBuild = "fighter",
RequiredResearch = "",
RequiredShipSubSystems = "",
DisplayPriority = 0,
DisplayedName = "$7000",
Description = "$7001"
},
{
Type = SubSystem,
ThingToBuild = "corvette",
RequiredResearch = "",
RequiredShipSubSystems = "",
DisplayPriority = 0,
DisplayedName = "$7002",
Description = "$7003"
},
{
Type = SubSystem,
ThingToBuild = "frigate",
RequiredResearch = "",
RequiredShipSubSystems = "",
DisplayPriority = 0,
DisplayedName = "$7004",
Description = "$7005"
},
}
Run Code Online (Sandbox Code Playgroud)
我如何在 Python 中使用类似的速记/语法糖来实现这一点?谢谢。
如何将浮点值舍入到最接近的“n”倍数?
例如,将 21.673 四舍五入到最接近的 8 倍数应得到 24。
并且,将 21.673 四舍五入到最接近的 4 倍数应得到 20。
我需要 JavaScript 的解决方案。
arrays ×1
dictionary ×1
excel ×1
javascript ×1
lua ×1
python ×1
qt ×1
qt-creator ×1
rounding ×1
ternary ×1
utf-8 ×1
vba ×1