Advertisement
GNOOR1S

Computercraft Flip Coin Programs

Jun 11th, 2023
1,299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.46 KB | None | 0 0
  1. print("Choose between Option 1 and Option 2")
  2. choice = io.read()
  3.  
  4. -- validate the user input
  5. while choice ~= "Option 1" and choice ~= "Option 2" do
  6.   print("Invalid choice. Choose between Option 1 and Option 2")
  7.   choice = io.read()
  8. end
  9.  
  10. -- generate a random number between 1 and 2
  11. if math.random(1, 2) == 1 then
  12.   print("You chose " .. choice .. ". Option 2 was not selected.")
  13. else
  14.   print("You chose " .. choice .. ". Option 1 was not selected.")
  15. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement