"be consistent" | |
PerlMonks |
1: # Howdy! This is my very first Perl script! I know it's kinda short 2: # but any response would be great. What I am trying to do next is to make 3: # it in a CGI/HTML format to put on a web page. Hints anyone? 4: 5: 6: 7: #!/usr/local/bin/perl -w 8: 9: print "Guess the number."; 10: print "DIRECTIONS:\nGuess a number between 1 and 100 inclusive.\n\n"; 11: $random = int(rand(100)+1); # I added 1 to the random 12: # number generator to push the 13: # possible numbers from 0-99 to 1-100 14: 15: for ($try=6;$try>0;$try--){ # $try is the number of tries you get (DUH!) 16: print "You have 1 try left. Use it wisely!\n\n" if($try ==1); 17: print "You have $try tries left.\n\n" if($try !=1); 18: print "What is your guess? -->"; 19: do { 20: $guess = <STDIN>; chomp $guess; 21: 22: }while (!$guess); 23: print "HA! HA! too HIGH.\n" if ($guess>$random); 24: print "OH! NO! too LOW.\n" if ($guess<$random); 25: if ($guess==$random){ 26: print "'Bout time you guessed it. Stupid head.\n\n" ; 27: exit; 28: } 29: } 30: print "The answer was $random. And so is your IQ.\n\n\nSTUPID!!\n\n"; 31: exit; 32: 33: 34: ############################################################ 35: # UPDATED --- 1/11/03 # 36: # NOTE: the problem with this is that it loops # 37: # printing the button text box ect. w/o giving you a # 38: # chance to guess. Still a work in progress. # 39: # Any generous monk out there willing to give me a # 40: # little nudge? # 41: ############################################################ 42: 43: 44: 45: #!/usr/local/bin/perl -w 46: 47: print "Content-type: text/html\n\n"; 48: use CGI; 49: $query = new CGI; 50: print "<HTML><HEAD><title>Guess the number.</title></HEAD><BODY>"; 51: print "<H1>DIRECTIONS:\nGuess a number between 1 and 100 inclusive.\n\n</H1>"; 52: $random = int(rand(100)+1); 53: 54: for ($try=6;$try>0;$try--){ 55: print "You have 1 try left. Use it wisely!\n\n" if($try ==1); 56: print "You have $try tries left.\n\n" if($try !=1); 57: print "What is your guess? -->"; 58: print '<INPUT TYPE="text" NAME="guess">'; 59: print '<INPUT TYPE = "submit">'; 60: print "HA! HA! too HIGH.\n" if ($guess>$random); 61: print "OH! NO! too LOW.\n" if ($guess<$random); 62: if ($guess==$random){ 63: print "'Bout time you guessed it. Stupid head.\n\n" ; 64: print"</BODY>"; 65: exit; 66: # print "The answer was $random. And so is your IQ.\n\n\nSTUPID!!\n\n";exit; 67: } 68: } 69: print "The answer was $random. And so is your IQ.\n\n\nSTUPID!!\n\n"; 70: print"</BODY>"; 71: exit;
|
---|
Replies are listed 'Best First'. | |
---|---|
•Re: Guess the number
by merlyn (Sage) on Dec 22, 2003 at 17:39 UTC | |
Re: Guess the number
by mkirank (Chaplain) on Jan 08, 2004 at 04:34 UTC | |
by chip_creep (Acolyte) on Jan 11, 2004 at 21:07 UTC | |
by Mongo Job (Initiate) on Feb 18, 2004 at 21:46 UTC | |
by Mongo Job (Initiate) on Feb 18, 2004 at 21:59 UTC | |
by chip_creep (Acolyte) on Feb 24, 2004 at 04:14 UTC | |
by chip_creep (Acolyte) on Feb 22, 2004 at 17:23 UTC |