Page 247 - Computer Science Class 11 Without Functions
P. 247

5.  math.factorial(num)
                  Function factorial() takes a positive integer as an input and returns the factorial of the number. For instance,
                the following function call returns the factorial of the number 5.

             >>> math.factorial(5)
                 120
            6.  math.gcd(num1, num2)
                  Function gcd() takes two integers as an input and returns the greatest common divisor of num1 and num2.
                For instance, the following function call returns 8 as the greatest common divisor of 16 and 24, both being divisible
                by 8.
             >>> math.gcd(16,24)
                 8
            7.  math.sin(num)
                  Function sin() takes a positive integer or floating point number in radians as an input and returns its arc sine
                value. For instance, the following function call returns the sine value of pi/2  (3.14/2 in radians) as the output:
             >>> math.sin(pi/2)
                 1.0
            8.  math.cos(num)
                  Function cos() takes a positive integer or floating point number in radians as an input and returns its cosine
                value. For instance, the following function call returns the cosine value of 1.0 (radians) as the output:

             >>> math.cos(0.0)
                 1.0


                     Give the function call that would yield cosine of an angle of 600? Recall that π radians = 1800.




            9.  math.tan(num)
                  Function tan() takes a positive integer or floating point number in radians as an input and returns its arc tan
                value. For instance, the following function call returns the tangent value of pi/4 (radians) as the output:
             >>> math.tan(pi/4)
                 0.9999999999999999
            10.1.1 Random Module

            Python  module  random  is  another  useful  module  that  enables  us  to  generate  random  numbers.  The  random()
            function of the random module enables us to generate a random number between 0 and 1.

             >>> import random
             >>> help(random.random)
                 Help on built-in function random:

                 random() method of random.Random instance
                 random() -> x in the interval [0, 1].
             >>> random.random()
                 0.4988834047541426
            Suppose we are playing a game between n players and need to randomly decide the player who will play at position
            first, second, third, etc. For this purpose, we need a function that can randomly generate a value between 1 to n.
            The function  randint() of the random module enables us to generate a random number between a and b, both
            inclusive.
             >>> help(random.randint)
                 Help on method randint in module random:



                                                                                                      Modules    245
   242   243   244   245   246   247   248   249   250   251   252