逻辑运算
检验大小(自测题)
题目:如果已知number变量n,那么如果需要判断n是否符合下面的条件:
3<n≤10
以下四行判断代码,正确的是?
(返回true即表示变量n符合要求)
n = 1--这个数可能是任意数字
print(n <= 10 and n > 3)
分支判断
判断三角形合法性(自测题)
你需要使用前面几章的知识,来完成下面的题目
已知三个number类型的变量a、b、c,分别代表三根木棒的长度
请判断,使用这三根木棒,是否可以组成一个三角形(两短边之和大于第三边)
如果可以组成,就打印出true
如果不可以,就打印false
--多改几个数值自行测试
a,b,c = 3,4,6
t = false
--补全代码
if (a+b>c) and (c>a and c>b) then
t = true
end
if (a+c>b) and (b>a and b>c) then
t = true
end
if (c+b>a) and (c<a and b<a) then
t = true
end
print(t)
函数
判断三角形合法性2(自测题)
你需要使用前面几章的知识,来完成下面的题目
已知三个number类型的变量a、b、c,分别代表三根木棒的长度
请判断,使用这三根木棒,是否可以组成一个三角形(两短边之和大于第三边)
如果可以组成,就打印出true
如果不可以,就打印false
function triangle(a,b,c)
t = false
--补全代码
if (a+b>c) and (c>a and c>b) then
t = true
end
if (a+c>b) and (b>a and b>c) then
t = true
end
if (c+b>a) and (c<a and b<a) then
t = true
end
return t
end
result = triangle(1,2,3)--传入值为三边长度,多改几个测试下
print(result)

1万+



被折叠的 条评论
为什么被折叠?



