Wednesday, 9 April 2025

GRADE 12 : PRACTICAL 1 : FUNCTIONS

 '''

GRADE 12 : PRACTICAL 1

Write a menu driven program to create the following functions:

a> accept() to accept the name of 10 areas & their PIN Codes in 2 lists.

b> search() to search for an area. If found, display the city and PIN Code, otherwise display 'Search Unsuccessful'

c> update() for updating the PIN Code of a certain area if found,otherwise display 'Update Unsuccessful'  

d> A function display() to populate the above 2 lists into a dictionary and display the same'''


area_list=[]

pin_list=[]


def menu():

    while True :

        ch=int(input("""MENU :

1>ACCEPT

2>SEARCH

3>UPDATE

4>DISPLAY

5>EXIT

Enter choice : """))

        if ch==1:

            accept()

        elif ch==2:

            search()

        elif ch==3:

            update()

        elif ch==4:

            display()

        else:

            break


def accept():

    for i in range(10):

        area=input("Enter area : ")

        pin=int(input("Enter pincode : "))

        area_list.append(area)

        pin_list.append(pin)

        

def search():

    a=input("Enter area to search : ")

    if a in area_list:

        i = area_list.index(a)

        print("Pincode is : ",pin_list[i])

    else :

        print("Search unsuccessful ")

        

def update():

    a=input("Enter area to updated : ")

    if a in area_list:

        i = area_list.index(a)

        print("Pincode is : ",pin_list[i])

        pin=int(input("Enter new pincode : "))

        pin_list[i]=pin     

    else :

        print("Update unsuccessful ")


def display():

    d=dict(zip(area_list,pin_list))

    print(d)


menu()






No comments:

Post a Comment