#32 Guessing Game

This is one of the simpler computer games. The program generates a random number in the interval 1 to 1,000 and asks you to guess it.

Guess right and you win. Guess wrong and the system adjusts the interval based on your guess and let's you try again.

This is a good game for first graders. It teaches them the basics of computer usage and how to follow instructions and even gives them an idea of how to create a binary search.

The Code

 1 use strict; 2 use warnings; 3 4 my $low = 1; # Current low limit 5 my $high = 1000; # Current high limit 6 7 # The number the user needs to guess 8 my $goal = int(rand($high))+1; 9 10 while (1) { 11 print "Enter a number between $low and $high: "; 12 13 # The answer from the user 14 my $answer ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.