Respuesta :
Answer:
Following are the program in the Perl Programming Language.
#set variable to 7
$gus = 7;
#set random number to the variable
$random = int(rand(100)) + 100;
#print message
print "Your name please: ";
#set variable to store name
my $name = <STDIN>;
chomp $name;
#print the random numbers with message ;
print "You Only Have Seven Guss to Find a Number\n";
print "Enter any number between 100 - 200\n";
#get number from the user
my $n = <STDIN>;
chomp $n;
#set the while loop
while( $gus > 0 )
{
#set if conditional statement
if( $n == $random)
{
print ("Congratulation, you Win the game in '$gus' gusses");
last;
}
elsif( $n < $random )
{
print ("Low Guss, Try Again \n");
}
else
{
print ("High Guss, Try Again \n");
}
#set variable to store value
my $n1 = <STDIN>;
chomp $n1;
#initialize the values
$n = $n1;
$gus = $gus-1;
}
#if guss is not found
if($gus == 0)
{
print "You have reached the maximum number of guss. Try Next Time\n";
}
#set variable to store file
open(my $f, '>', 'report.txt');
print $f " '$n' '$gus'\n";
#close file
close $f;
print "done\n";
Output:
Your name please: Shiva
You Only Have Seven Guss to Find a Number
Enter any number between 100 - 200
150
High Guss, Try Again
130
High Guss, Try Again
110
High Guss, Try Again
105
Congratulation, you Win the game in '4' gusses
done
Explanation:
Here, we set an integer type variable "gus" and assign value to 7 and then, we set variable "random" in which we store the random number from 100 to 200.
Then, we print message and get input string from the user in variable "name".
Then, we get number from user between 100 - 200 and set the while loop inside it we set the if-else statement to check the following input is equal to the ransom number or not.
Finally, we follow the following steps and set file.