Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help with Perl, using perl 5 Exercise A7 The following statements set the v

ID: 3600768 • Letter: N

Question

Need help with Perl, using perl 5

Exercise A7

The following statements set the values:

$x = 3;

$y = 0;

$z = -4;

Then, which of the following expressions evaluate to true, and which evaluate to false?

!( $x < $y ) = True

!( $x >= $y ) False

!( (4 + 5 * $y) >= $z -2 ) && ( $z - 2 )

!($x) && !($y) || !($z)

Exercise A8

Code a single statement, which uses the && operator, and produces the same results as this code:

if ( $x < 10 )

    {

    $x++;

    }

Exercise A9

Code a single statement, which uses the || operator, and produces the same results as this code:

unless ( $x < 10 )

    {

    $x++;

    }

Explanation / Answer

Exercise A7
The following statements set the values:
$x = 3;
$y = 0;
$z = -4;
Then, which of the following expressions evaluate to true, and which evaluate to false?
a) !( $x < $y ) = True
Answer: Evaluates True
Program:

$x = 3;
$y = 0;
$z = -4;
if (!( $x < $y ))
{
print "True";
}
else
{
print "False";
}
Output: True

b) !( $x >= $y ) False
Answer: Evaluates True
Program:

$x = 3;
$y = 0;
$z = -4;
if (!( $x >= $y ))
{
print "False";
}
else
{
print "True";
}
Output: True

c) !( (4 + 5 * $y) >= $z -2 ) && ( $z - 2 )
Answer: Evaluates False
Program:

$x = 3;
$y = 0;
$z = -4;
if (!( (4 + 5 * $y) >= $z -2 ) && ( $z - 2 ))
{
print "True";
}
else
{
print "False";
}
Output:False

d) !($x) && !($y) || !($z)
Answer: Evaluates False
Program:

$x = 3;
$y = 0;
$z = -4;
if (!($x) && !($y) || !($z))
{
print "True";
}
else
{
print "False";
}
Output: False

Exercise A8 :
$x = 3;
if ( $x < 10 && $x > 2 )
{
$x++;
}
print $x;
Output: 4

Exercise A9:
$x = 3;
unless ( $x < 10 || $x >10)
{
$x++;
}
print $x;
Output: 3