Page 438 - Ai_417_V3.0_C9_Flipbook
P. 438

S. No.                                          Program

                    13    Create a list in Python of children selected for science quiz with following names- Arjun, Sonakshi,
                          Vikram, Sandhya, Sonal, Isha, Kartik. Perform the following tasks on the list in sequence-

                             a) Print the whole list
                             b) Delete the name "Vikram" from the list
                             c) Add the name "Jaya" at the end
                             d) Remove the item which is at the second position.

                          Names=["Arjun", "Sonakshi", "Vikram", "Sandhya", "Sonal", "Isha", "Kartik"]
                          print(Names)
                          Names.remove("Vikram")
                          print(Names)
                          Names.append("Jaya")
                          print(Names)
                          Names.pop(1)
                          print(Names)
                          Output:
                          ['Arjun', 'Sonakshi', 'Vikram', 'Sandhya', 'Sonal', 'Isha', 'Kartik']
                          ['Arjun', 'Sonakshi', 'Sandhya', 'Sonal', 'Isha', 'Kartik']
                          ['Arjun', 'Sonakshi', 'Sandhya', 'Sonal', 'Isha', 'Kartik', 'Jaya']
                          ['Arjun', 'Sandhya', 'Sonal', 'Isha', 'Kartik', 'Jaya']

                    14    Create a list num=[23,12,5,9,65,44]
                             a) Print the length of the list
                             b) Print the elements from second to fourth position using positive indexing
                             c) Print the elements from position third to fifth using negative indexing

                          L1=[23,12,5,9,65,44]
                          print(len(L1))
                          print(L1[1:4])
                          print(L1[-4:-1])
                          Output:
                          6
                          [12, 5, 9]
                          [5, 9, 65]

                    15    Create a list of first 10 even numbers, add 1 to each list item and print the final list.
                          L1=[]
                          for x in range(2,21,2):
                            L1.append(x)
                          print(L1)
                          for i in range(len(L1)):
                            L1[i]+=1
                          print(L1)
                          Output:
                          [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
                          [3, 5, 7, 9, 11, 13, 15, 17, 19, 21]




                    436     Touchpad Artificial Intelligence (Ver. 3.0)-IX
   433   434   435   436   437   438   439   440   441   442   443