Page 320 - AI Ver 1.0 Class 9
P. 320

print(alpha)
           Output will be: ['e', 'd', 'c', 'b', 'a']
           • sort(): This function sorts the list in ascending or descending order. This is done "in the list itself" and works for
           the list with values of the same data types. For example,

                city=["Delhi", "Mumbai", "Kolkata", "Chennai"]
                 city.sort() #sorts the list by default in ascending order
                 print(city)
           Output will be: ["Chennai", "Delhi", "Kolkata", "Mumbai"]
                                                                                                                                                                                   Exercise
                city.sort(reverse=True)#sorts the list descending order
           Output will be: ["Mumbai", "Kolkata", "Delhi", "Chennai"]
           • index(): It returns the index number of the value given in the function. For example,

           city=["Delhi", "Mumbai", "Kolkata", "Chennai"]                                                                                                                      Solved Questions
          city.index("Kolkata")                                                                                                                                         SECTION A (Objective Type Questions)
           Output will be: 2                                                                                                                    uiz
           city.index("Pune")                                                                                                         A.  Tick ( ) the correct option.
           Output will be: ValueError
                                                                                                                                          1.  Which of the following symbols is used in flowcharts to take an input from the user?
           It returns ValueError exception if the value is not found in the list.                                                           a.  Diamond                                        b.  Rectangle
           • count(): This function counts the number of occurrences of the specified value in the given list. If the value
           doesn’t exist, then the function returns 0. For example,                                                                         c.  Oval                                           d.  Parallelogram

           marks = [56, 67, 45, 78, 56, 78, 12]                                                                                           2.  Coding and implementation is the ………………………. step in problem solving.
                                                                                                                                            a.  First                                          b.  Last
          marks.count(78)
           Output will be: 2                                                                                                                c.  Third                                          d.  Second

          marks.count(10)                                                                                                                 3.  Which of the following symbols is used to display the decision-making statements in a flowchart?
           Output will be: 0    # 10 does not exist in the list.
                                                                                                                                            a.  Rectangle                                      b.  Line
                                                                                                                                            c.  Diamond                                        d.  Oval
                  At a Glance                                                                                                             4.  Which of the following is the step-by-step approach in simple English-like statements?


              • A program is written in any programming language which the computer can understand and execute.                             a.  Algorithm                                      b.  Selection
              • Control structures are a set of instructions that controls the flow of instructions in a program.                           c.  Flowchart                                      d.  Sequence
              • An algorithm is a step-by-step approach to identify and solve a problem in a finite time.
              • A flowchart is a graphical representation of an algorithm.                                                                5.  Which of the following is/are powerful tools for learning programming?
              • Python is a general-purpose, object oriented, easy to learn and high-level programming language.                            a.  Flowchart                                      b.  Algorithm
              • Instructions written in a source code that are executed by a Python interpreter are called statements.                      c.  Both a and b                                   d.  None of these
              • Tokens are the smallest meaningful unit of a program.
              • Identifiers are the user defined names of variables, list, dictionary, tuples, classes etc.                               6.  Which of the following is the valid name for (an) identifier(s) in Python?
              • Variable is a name given to a memory location to hold a specific value.                                                     a.  Test#4                                         b.  Rollno
              • List is a collection of heterogeneous data arranged in a sequence.                                                          c.  9thClass                                       d.  else
              • The elements of a list can be accessed by using its index number starts with 0 (zero).
              • The + operator is used to concatenate the list with another list.                                                         7.  Which of the following is a valid logical operator?
              • The * operator is used to replicate a list specific number of times.                                                        a.  and                                            b.  !=
              • The comparison of the lists is done using comparison operators >, <, >=, <=, != and ==.                                     c.  +                                              d.  >=
              • The append( ) Function appends a single element with the given value(any datatype) at the end of the list.




                  318   Touchpad Artificial Intelligence-IX
   315   316   317   318   319   320   321   322   323   324   325