Q. In the Python shell, do the following:


(i) Define a variable named states that is an empty list.

(ii) Add 'Delhi' to the list.

(ii) Now add 'Punjab' to the end of the list.

(iv) Define a variable states2 that is initialized with 'Rajasthan', 'Gujrať, and 'Kerala'.

(v) Add 'Odisha' to the beginning of the list.

(vi) Add ‘Tripura’ so that it is the third state in the list.

(vii) Add 'Haryana' to the list so that it appears before 'Gujrať. Do this as if you DO NOT KNOW where 'Gujrať is in the list.

Hint. See what states2.index("Rajasthan") does. What can you conclude about listname.index(item) does ? what

(viii) Remove the 5th state from the list and print that state's name.


Answer :


1 = states = []

2 = states.append (“Delhi”)

3 = states.append (“Punjab”)

4 = states2 = ['Rajasthan', ‘Gujrat’, 'Kerala']

5 = states2.insert (0, ‘Odisha’)

6= states2.insert (2, ‘Tripura’)

7 = states2.insert (states.index('Gujrat'), 'Haryana')

8 = print( states2.pop(4) )

8 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. I'm this year syllabus of ip is totally changed so what this all questions are important for in this exam

    ReplyDelete
    Replies
    1. If you are in class 11 . Then it is important But if you are in class 12 then it is not important ..

      Delete
  2. I'm this year syllabus of ip is totally changed so what this all questions are important for in this exam

    ReplyDelete
    Replies
    1. If you are in class 11 . Then it is important But if you are in class 12 then it is not important ..

      Delete
  3. In the 8th part it also asked for printing that states name

    ReplyDelete
  4. The 7th part... The question was asking to answer it as we don't know on where/what index is Gujarat in... In the list

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post