Example 6 (4p) A Boolean expression is an expression that is evaluated to either
ID: 3874663 • Letter: E
Question
Example 6 (4p) A Boolean expression is an expression that is evaluated to either true or false. You have used Boolean expressions as conditions in e.g. if-statements You are rolling two dice, die1 and die2. Write expressions to find: a) b) c) d) A result when one die shows 2 eyes and the other more than 3 eyes. (1p) A result when both dice show less than 2 eyes. (1p) A result when the sum of the two dice is larger than 8 eyes. (1p) A result when the difference between the dice is larger than 2. (1p)Explanation / Answer
Boolean Expression
a) Expression for one die shows 2 eyes and the other more than 3 eyes?
ans) if(die1==2 && die2>3)
----------------------------------------------------------------------------------------------------------------------
b) Expression for both dice show less than 2 eyes?
ans) if(die1<2 && die2<2)
-----------------------------------------------------------------------------------------------------------------------------
c) Expression for sum of the two dice is larger than 8 eyes ?
ans) if((die1+die2) >8)
--------------------------------------------------------------------------------------------------------------------------------
d) Expression for difference between the dice is larger than 2?
ans) if((die1- die2)>2)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.