Skip to content

Instantly share code, notes, and snippets.

@rozer007
Created December 2, 2021 11:27
Show Gist options
  • Save rozer007/09a2fe9f41857a5615bfd76228464b45 to your computer and use it in GitHub Desktop.
Save rozer007/09a2fe9f41857a5615bfd76228464b45 to your computer and use it in GitHub Desktop.
Math function and conditional in lua
Q1. How can we generate a same random number all the time?
ans: We will have to set the randomseed(constant) value to some constant then it will generate same random all the time.
Q2. how can we create a local variable in lua?
ans: we have use local keyword to create a local variable in lua. eg local x=10.
Q3.What is the syntax of ternary operator in lua?
ans: var_name = condition and <if true> or <if false> eg. bool=1>10 "right" or "wrong"
Q4.What is the math function to find the maximum between two numbers?
ans: math.max() function is used to find the max betwwen two number.
Q1. what is the correct way to generate a random number from 0 to 1?
a) math.random(0,1)
b) math.random()
c) all the above
d) none of the above
ans: d)
Q2) What will the output of this statements:
print(5.2%3)
a) 2
b) 2.2
c) 2.0
d) none of the above
ans: a)
Q3) What will be the output of this statements:
b=(3+3)and(2+2)
print(b)
a) true
b) false
c) 4
d) 6
ans: c)
Q4) Select the correct output of this expression:
b=5%3-2*3+4
a)-4
b) 0
c) 12
d) 3
ans: b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment