[Lua Learning] Guess number games

Source: Internet
Author: User

1 --set random number seed2 Math.randomseed(Os.time())3 Math.random()4 5 Print("Guess number Game (0-100)")6 7 LocalLimit =68 LocalAnswer =Math.random(0, -)9 Ten  while true  Do One     Print("remaining".. Limit:"Second Chance:") A     LocalGuess =Io.read("*number") -     ifGuess = = Answer Then -         Print("Congratulations, you guessed it! ") the          Break -     ElseIfGuess < answer Then -         Print("guess it's too small! ") -     ElseIfGuess > Answer Then +         Print("guess too much! ") -     End +Limit = Limit-1 A     ifLimit = =0  Then at         Print("I'm sorry I ran out of chances! The correct answer is:".. Answer."!") -          Break -     End - End

PS: Do not do error input processing, if the input is not a number, the program will be wrong. When the number entered is not within the range of 0 to 100, it will not be alerted.

Operation Result:

[Lua Learning] Guess number games

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.