Page 292 - Data Science class 11
P. 292

b. Combine the modulo operator with addition to find the result of 17 + 5 %% 3.
          Ans.  Output
               19

               (This is because first modulus operation is done and then addition is performed).
          16.  Variable Operations:

               a. If x = 6 and y = 2, calculate the value of x^y.
          Ans.  Output
              [1]  36

               b. Using two variables, perform an operation that involves both addition and subtraction.
          Ans.  a=3

               b=4
               (a+b)-a
               Output
               [1]  4

          17.  Numeric Conversions:
               a. Convert the result of 5 / 2 to an integer using the as.integer() function.

          Ans.  as.integer(5/2)
              Output
               [1]  2

               b. Discuss the differences between the / and %/% operators in R.
          Ans.  / is the division operator which finds the quotient whereas %% is the modulo operator which is used find the
              remainder of the division operation.

          18.  Order of Evaluation
               a. Given the expression a <- 3; b <- 5; c <- 2, explain the result of a * b + c.
          Ans.  First multiplication and then addition.

               3*5+2
               Output
               17

               b. Discuss the importance of parentheses in controlling the order of evaluation.
          Ans.  Parenthesis changes the order of evaluation. It has the highest precedence in an expression.
          19.  Error Handling

               a. Identify and correct any syntax errors in the expression 10 + * 3.

          Ans.  Two operators cannot be given together.
               The correct way of writing the expression is
               10+3 or 10 * 3







          290   Touchpad Data Science-XI
   287   288   289   290   291   292   293   294   295   296   297