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

d.  math.log(100,10)
                    e.  math.log(100,math.e)
                    f.  math.sin(math.pi/4)
                    g.  math.tan(2*math.pi)
                    h.  math.gcd(18, 34)
                    i.  statistics.mean( [150, 154, 160, 161, 165] )
                    j.  math.factorial(10)
                 3.  Give all possible outputs that may be produced when the following code is executed.

                    import random
                    continents = ['Asia', 'Australia', 'South America', 'North America', 'Europe', 'Antarctica']
                    option1 = random.randint(2, 4)
                    option2 = random.randint(3, 5)
                    for x in range(option1, option2):
                        print(continents[x], end = '#')
               Ans.  Europe#
                    North America#Europe#
                    North America#
                    South America#
                    South America#North America#Europe#
                    South America#North America#
                 4.  What will be the output of the given code?
                    def calculate(var1,var2=2, var3=0):
                        total=var1+var2+var3
                        print(total)
                    calculate(4)
               Ans.  6

              Solved Programming Questions

                 1.  Write a function max3(n1, n2, n3) that finds the maximum out of three numbers n1, n2, and n3.
               Ans.  def max3(n1, n2, n3):

                       '''
                       Objective: To find maximum of three numbers
                       Input Parameters: n1, n2, n3 - numeric values
                       Return Value: maximum of n1, n2, n3 - numeric value
                       '''
                       '''
                       Approach:
                        Compare each number with the other two numbers. Assign the maximum to the maximum
                       among n1, n2, and n3.
                       '''

                       if (n1 >= n1) and (n1 >= n3):
                           maximum = n1
                       elif (n2 >= n1) and (n2 >= n3):
                           maximum = n2
                       else:

               242   Touchpad Computer Science (Ver. 2.0)-XI
   251   252   253   254   255   256   257   258   259   260   261