Advertisement
Kodos

Random Number Guessing Game

Feb 18th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.59 KB | None | 0 0
  1. print("Welcome to the Guessing Game! Enter a number!")
  2. guess = tonumber(read())
  3. number = math.floor(math.random() * 100)
  4. count = 1
  5. while number ~= guess and count < 20 do
  6.   if guess < number then
  7.     print("Your number was too low! Try another number.")
  8.     guess = tonumber(read())
  9.     count=count + 1
  10.   else
  11.     print("Your number was too high! Try another number.")
  12.     guess = tonumber(read())
  13.     count=count + 1
  14.   end
  15. end
  16. if count == 20 and guess ~= number then
  17.   print("You lose! The number was " .. number .. "!")
  18. else
  19.   print("You won! It took you " .. count .. " tries!")
  20. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement