In: Computer Science
hours = 40;
status= True;
overtime = False
What is the value of each of the following Boolean expressions? [4 marks]
i. Given status = True, !status is opposite of status, hence !status = False
we need to find status and !status. and expressions returns true only if both the expressions are true. Otherwise and returns false . Hence
status and !status = True and False = False
ii. As shown in the above section, status = True and !status = False.
We need to find status or !status. or returns true if either of the expressions it evaluates is true. or return false only if both expressions it evaluates is false. Hence,
status or !status = True or False = True
iii. Given overtime = False and hours = 40.
The expression hours>=40 return True because hours=40
The expression overtime == (hours>=40) checks whether the variable overcome and the output of hours>=40 are the same.
But overtime = False and hours>=40= True. Hence the expression returns False because LHS and RHS are not the same.
iv. Here LHS = False.
RHS = hours>40 . Since hours = 40, this return False. Hence RHS = False
==> LHS = RHS which is what the == expression checks. Hence the expression returns True.