Q. Write a program to input names of n students and store them in a tuple. Also, input a name from the user and find if this student is present in the tuple or not.


We can accomplish these by:

(a) Writing a user defined function

(b) Using the built-in function


Answer :-


def find( name):
    if name in tup :
        return name, "is present in ",tup
    else :
        return name, "is not present in ",tup
    
tup = eval( input ("Enter a tuple containing name of student :-"))
nam = input("Enter the name of student :-")

print( find( nam ) )


Output :-


Enter a tuple containing name of student :-("Path","Walla","portal","express","computer")
Enter the name of student :-Path
('Path', 'is present in ', ('Path', 'Walla', 'portal', 'express', 'computer'))
>>>

Enter a tuple containing name of student :-("Path","Walla","portal","express","computer")
Enter the name of student :-python
('python', 'is not present in ', ('Path', 'Walla', 'portal', 'express', 'computer'))
>>>

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post