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

Case-based Questions

                 1.  Abhilasha wants to create a program for her younger sister who is learning spellings of each digit. She wants to create a
                    dictionary that stores a digit and its corresponding spelling as key-value pairs. So, the dictionary will have items as 1:"One",
                    2:"Two, 3:"Three", …, 9:"Nine". Further, she wants to develop a program to accept a number as input and then display the
                    spellings for its digits. For example, if the user enters 502, the output should be Five Zero Two
                 2.  Sukrit is a programmer in an IT company. He has been assigned the task of creating a Python program that will accept the
                    name and date of birth of each employee as input and store name and date of birth as key-value pairs of a dictionary. Sukrit
                    wishes to display the data of the employees ordered with respect to their names arranged in alphabetical order.  Help him
                    to complete the task.

                                              NCERT Exercise Solutions


                 1.  What will be the output of the following statements?
                    i.  list1 = [12,32,65,26,80,10]
                      list1.sort()
                      print(list1)
                    ii.  list1 = [12,32,65,26,80,10]
                      print(sorted(list1))
                      print(list1)
                    iii.  list1 = [1,2,3,4,5,6,7,8,9,10]
                      print(list1[::-2])
                      print(list1[:3] + list1[3:])
                    iv.  list1 = [1,2,3,4,5]
                      print(list1[len(list1)-1])
               Ans.  i. [10, 12, 26, 32, 65, 80]
                    ii. [10, 12, 26, 32, 65, 80]
                       [12, 32, 65, 26, 80, 10]
                    iii. [10, 8, 6, 4, 2]
                        [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
                    iv.  5

                 2.  Consider the following list myList. What will be the elements of myList after the following two operations:
                    myList = [10,20,30,40]
                    i.  myList.append([50,60])
                    ii.  myList.extend([80,90])
               Ans.  Elements of myList after given operations are
                    i.  [10,20,30,40,[50,60]]
                    ii.  [10,20,30,40,[50,60],80,90]
                 3.  What will be the output of the following code segment:
                    myList = [1,2,3,4,5,6,7,8,9,10]
                    for i in range(0,len(myList)):
                         if i%2 == 0:
                              print(myList[i])
               Ans.  Above code print even positioned element of myList.
                    1
                    3
                    5
                    7
                    9

               430   Touchpad Computer Science (Ver. 2.0)-XI
   439   440   441   442   443   444   445   446   447   448   449