[Courses] [Perl] Perl course Part 4
Morgon Kanter
morgon at surgo.net
Mon Apr 28 15:42:42 EST 2003
This one time, at band camp, Alice Wood <alice at schiffwood.co.uk> wrote:
> 3) Exercise
>
> Write a program that will ask the user to guess a number. The number
> will be predefined at the beginning of your program.
>
> Example
>
> #!usr/bin/perl -w
> use strict;
>
> my $target = 17;
>
> #Rest of your program
Here's the answer (don't look down if you don't want to be spoiled)
--------------- begin number.pl ----------------
use strict;
my $number = 17;
while(1) {
print "Enter your guess: ";
my $guess = <STDIN>;
if($guess == $number) {
print "Correct!\n";
exit 0;
} else {
print "Wrong, try again :(\n";
}
}
------------- end number.pl ---------------
venthorn at surgo:~$ perl number.pl
Enter your guess: 4
Wrong, try again :(
Enter your guess: 5
Wrong, try again :(
Enter your guess: 17
Correct!
venthorn at surgo:~$
Morgon
--
You said homosexuals form a small percentage of the population. So
do Jews. Is that a reason to deny someone equality?
- Richard Marceau
More information about the Courses
mailing list