basic python-7(Qna)

Q1: In the Python shell, do the following…
A1: Here is a simple Python script that accomplishes this:
                # (i) Define a variable named states that is an empty list.
                states = []

                # (ii) Add 'Delhi' to the list.
                states.append('Delhi')

                # (iii) Now add 'Punjab' to the end of the list.
                states.append('Punjab')

                # (iv) Define a variable states2 that is initialized with 'Rajasthan', 'Gujarat', and 'Kerala'.
                states2 = ['Rajasthan', 'Gujarat', 'Kerala']

                # (v) Add 'Odisha' to the beginning of the list states2.
                states2.insert(0, 'Odisha')

                # (vi) Add 'Tripura' so that it is the third state in the list states2.
                states2.insert(2, 'Tripura')

                # (vii) Add 'Haryana' to the list states2 so that it appears before 'Gujarat'.
                states2.insert(states2.index('Gujarat'), 'Haryana')

                # (viii) Remove the 5 th state from the list states 2 and print that state's name.
                print(states2.pop(4))
                

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top