Advertisement
ElijahCrafter

Untitled

Feb 29th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.81 KB | None | 0 0
  1. -- Function to simulate a coin flip
  2. local function coinFlip()
  3.     local randomNumber = math.random(1, 2) -- Generate a random number (1 for heads, 2 for tails)
  4.     if randomNumber == 1 then
  5.         return "Heads"
  6.     else
  7.         return "Tails"
  8.     end
  9. end
  10.  
  11. -- Main program
  12. function main()
  13.     print("Welcome to the Coin Flip Simulator!")
  14.     while true do
  15.         print("\nPress any key to flip the coin, or type 'exit' to quit.")
  16.         local input = read() -- Read user input
  17.         if input:lower() == "exit" then
  18.             print("Exiting the program...")
  19.             break -- Exit the loop
  20.         else
  21.             local result = coinFlip()
  22.             print("You got: " .. result)
  23.         end
  24.     end
  25.     print("Thank you for using the Coin Flip Simulator!")
  26. end
  27.  
  28. -- Start the program
  29. main()
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement