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) )
I'm this year syllabus of ip is totally changed so what this all questions are important for in this exam
ReplyDeleteIf you are in class 11 . Then it is important But if you are in class 12 then it is not important ..
DeleteI'm this year syllabus of ip is totally changed so what this all questions are important for in this exam
ReplyDeleteIf you are in class 11 . Then it is important But if you are in class 12 then it is not important ..
DeleteIn the 8th part it also asked for printing that states name
ReplyDeleteSorry, I have corrected it.
DeleteThe 7th part... The question was asking to answer it as we don't know on where/what index is Gujarat in... In the list
ReplyDeleteSorry, Now I have corrected it.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )