Page 7 - PYTHON-12
P. 7

21.  Find and write the output of the following Python code:                                   (2)

               def Display(str):
                  m=""
                   for i in range(0,len(str)):
                    if i%2 ==0:
                       m=m+str[i].lower()
                    else:
                       m=m+str[i].upper()
                  print(m)
               Display('Program@Class12')
           Ans.  pRoGrAm@cLaSs12
            22.  What possible output(s) is expected to be displayed on screen at the time of execution of the program from
               the following code? Justify your answer.                                                    (2)

               import random
               alpha=['T','U','V','W']
               dig=[2,6,7,3]
               print('The Winner is : ',end=" ")
               print(alpha[random.randint(0,3)],end=" ")
               for i in range(4):
                  print(dig[i+random.randint(0,2)],end=" ")
                (a)  The Winner is : T 7 3 6              (b)  The Winner is : W 2 6 7 5
                (c)  The Winner is : V 6 6 0              (d)  The Winner is : U 2 7 3
           Ans.  (a)  and  (d)
                   Any alphabet followed by digits from dig[ ]
                    i=0
                    0+0 dig: 2
                    0+1 dig: 6
                    0+2 dig: 7
                    i=1
                    1+0 dig: 6
                    1+1 dig: 7
                    1+2 dig: 3
                    i=2
                    2+0 dig: 7
                    2+1 dig: 3
            23.  Predict the output of the Python code given below:                                 (1 + 1 = 2)
               def JDI(N1,N2=1):
                  if type(N1)==list:
                    return N1[N2]
                  else:
                    return N1-N2
                  print(N1,N2,sep='#',end=' ')
               NUM=[15,20]
               NUM.append(JDI(NUM,0))
               NUM.append(JDI(10))
               print(NUM)
                                                          OR





          A.32                                                                     Computer Science with Python–XII
   2   3   4   5   6   7   8   9   10   11   12