Page 248 - Computer Science V2.0 Class 11
P. 248

2   math.floor(num)       Integer or floating point   Floor(lowest closest   >>> math.floor(13.3)
                                            number                  integer) value of num      13
                                                                                          >>> math.floor(-15.4)
                                                                                              -16
                  3   math.fabs(num)        Integer or floating point   Absolute value of num  >>> math.fabs(-14.7)
                                            number                  (returns floating         14.7
                                                                    point number as
                                                                    the absolute          >>> math.fabs(62.1)
                                                                    value)                    62.1
                  4   math.                 Positive integer        Factorial of num      >>> math.factorial(5)
                      factorial(num)                                                          120
                  5   math.                 Integer or floating point   num1%num2         >>> math.fmod(19,3)
                      fmod(num1,num2)       numbers                 (sign of num1)            1.0

                  6   math.                 Integers                Greatest common       >>> math.gcd(56,78)
                      gcd(num1,num2)                                divisor of num1 and       2
                                                                    num2
                                                                                          >>> math.gcd(-10,4)
                                                                                              2
                  7   math.                 Integers or floating point  num1 num2         >>> math.pow(14,3)
                      pow(num1,num2)        numbers                 num1  raised  to  the      2744.0
                                                                    power of num2         >>> math.pow(-4,2)

                                                                                              16.0
                  8   math.sqrt(num)        Positive integer or     Square root of num    >>> math.sqrt(25)
                                            floating point number                             5.0
                                                                                          >>> math.sqrt(40.5)
                                                                                              6.363961030678928
                  9   math.sin(num)         Integer or floating point   Arc  Sine  of  num  in  >>> math.sin(0)
                                            number in radians       radians                   0.0
                                                                                          >>> math.sin(0.2)
                                                                                              0.19866933079506122
                 10   math.cos(num)         Integer or floating point   Arc cosine of num  in  >>> math.cos(0)
                                            number in radians       radians                   1.0
                                                                                          >>> math.cos(10)
                                                                                              -0.8390715290764524
                 11   math.tan(num)         Integer or floating point   Arc tangent of num in  >>> math.tan(0)
                                            number in radians       radians                   0.0

                                                                                          >>> math.tan(1)
                                                                                              1.5574077246549023
              9.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

               234   Touchpad Computer Science (Ver. 2.0)-XI
   243   244   245   246   247   248   249   250   251   252   253