Page 427 - Ai_417_V3.0_C9_Flipbook
P. 427

9.  To store only integers in a new list by copying from the given list.
                   Ans.  L=[12,"abc",45.6,True,34,45]
                       L2=[]
                       for i in L:
                           if type(i)==int:
                               L2.append(i)
                       print(L2)
                    10.  Search a specific value and display its number of occurrences in a list.
                   Ans. L=[10,23,45,10,12,34,10,56]
                       s=int(input("Enter value you want to search: "))
                       count=0
                       for i in L:
                           if i==s:
                               count+=1
                       print(s," occurs ",count," times")



                                                       Unsolved Questions

                                                   SECTION A (Objective Type Questions)
                          uiz

                 A.  Tick ( ) the correct option.
                    1.  Which of the following is not the conditional statement in Python?
                       a.  if Statement                                  b.  if...elif...else Statement

                       c.  if…else Statement                             d.  for Statement

                    2.  Which of the following is a looping statement in Python?
                       a.  for statement                                 b.  while statement
                       c.  Both a and b                                  d.  None of these

                    3.  Which of the following statements allows to repeat a task for a fixed number of times?
                       a.  for statement                                 b.  if…else statement
                       c.  while statement                               d.  continue statement

                    4.  Which of the following can be a part of a list?
                       a.  String values                                 b.  Integer values

                       c.  List                                          d.  All of these
                    5.  If a list named L1 contains 4 elements, then which of the following can be used to access the last element of the L1 list?

                       a.  L1[4-1]                                       b.  L1[4]
                       c.  L1[-1]                                        d.  Both a and c

                 B.  Fill in the blanks.
                    1.  An ………………………. uses simple English-like statements.

                    2.  If A = 10 then the statement: if A > 5: print(A); will display ………………………. as an output.
                    3.  ………………………. uses symbols for writing a set of instructions.

                                                                                        Introduction to Python  425
   422   423   424   425   426   427   428   429   430   431   432