Wednesday, 9 April 2025

GRADE 12 : PRACTICAL 2 : FUNCTIONS

 '''

Write a menu driven program for the following functions:

1. accept(roll,name,score) :store student details in a

dictionary as :{roll : [name,score]}.

It will invoke function assign().

2. assign(roll): assign remarks as per the score,

and updates dictionary to : {roll : [name,score,remarks]}

------------------

|SCORE | REMARK  |

|>=50     | Selected      |

|<50       | Rejected      |

------------------

3. display(): view all the students who are selected.

4. search(roll): return the corresponding name and remark '''


d={}


def menu():

    while True:

        ch=int(input("""MENU:

1.Accept

2.Display

3.Search

4.Exit"""))

        if ch==1:

            roll=int(input("Enter Roll number : "))

            name=input("Enter name name : ")

            score=int(input("Enter Score : "))

            accept(roll,name,score)

        elif ch==2:

            display()

        elif ch==3:

            roll=int(input("Enter roll no to be searched"))

            print(search(roll))

        else:

            break


def accept(roll,name,score):

    d[roll] = [name,score]

    assign(roll)

    

def assign(roll):

    if d[roll][1]>=50:

        remark='Selected'

    else:

        remark='Rejected'

    d[roll].append(remark)

    

def display():

    for key in d:

        if d[key][2]=='Selected':

            print(d[key])


def search(roll):

    if roll in d.keys():

        return d[roll][0],d[roll][2]

    else:

        return 'Roll not found'


menu()


No comments:

Post a Comment