random number test in Lua - E and J helped
This commit is contained in:
BIN
lua/Notes/help1.png
Normal file
BIN
lua/Notes/help1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 77 KiB |
10
lua/randTest.lua
Normal file
10
lua/randTest.lua
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
io.write("Pick a number: ")
|
||||||
|
local number = io.read("*n")
|
||||||
|
local randnum = math.random(1, number)
|
||||||
|
print("The number is ", randnum)
|
||||||
|
-- ask to rerun script
|
||||||
|
print("Run again (y/n)?")
|
||||||
|
local cmd = io.read()
|
||||||
|
if cmd == "y" then
|
||||||
|
dofile("randTest.lua")
|
||||||
|
else end
|
||||||
26
lua/randTestHelped.lua
Normal file
26
lua/randTestHelped.lua
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
-- Assistance from a friend
|
||||||
|
|
||||||
|
-- Instantiate all the things
|
||||||
|
local run = true
|
||||||
|
local cmd, number, randnum
|
||||||
|
|
||||||
|
-- Start a loop
|
||||||
|
while run == true do
|
||||||
|
-- Get the users initial number
|
||||||
|
print("Pick a number: ")
|
||||||
|
number = io.read("*n")
|
||||||
|
|
||||||
|
-- Do some mathemagic
|
||||||
|
randnum = math.random(1, number)
|
||||||
|
print("The number is ", randnum)
|
||||||
|
|
||||||
|
-- Ask to rerun script
|
||||||
|
io.read()
|
||||||
|
print("Run again (Y/n)?")
|
||||||
|
cmd = io.read("*l")
|
||||||
|
|
||||||
|
-- Exit if the user doesn't want to go again
|
||||||
|
if string.lower(cmd) ~= "y" then
|
||||||
|
run = false
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user