Wednesday, 9 April 2025

3. Write a program in Python, with separate user defined functions to perform the following operations on Stack 'City'.

Write a program in Python, with separate user defined functions to perform the following operations on Stack 'City'.

(a) - Push the pin code and name of the city in the stack 'City'
(b) - Display the latest added element in the stack 'City'


Solutions:


City=[]
data=[['Delhi',110001],['Sonipat',152364],['Khatauli',251201]]

def Push_City():
    for i in data:
        City.append(i)
    

def Display_City():
    L=len(City)
    print(City[L-1])

Push_City()
Display_City()

No comments:

Post a Comment