Number-Guessing Game

Number-Guessing Game


This number-guessing game seems simple enough when you're a little kid: Someone picks a number and you try to guess it. In this script, a computer is doing the pseudo-random number generation, which is a lot more unpredictable than your friend picking his favorite number. As I wrote this, I got to thinking, "This sounds an awful lot like a game adults play—the lottery." How crazy is that? The same game that entertained you as a kid is still entertaining as an adult. Although the payoff is a lot better in the lottery, the odds are a lot worse. The bottom line is that this game is all about chance.

The Code

 puts "\nWelcome to the number-guessing game!\n\n\n\n" print "What difficulty level would ...

Get Wicked Cool Ruby Scripts now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.