Page 433 - Computer Science Class 11 With Functions
P. 433
key : element to be searched
Return Value:
True: if key is found in the tuple, False otherwise
index:
if search succeeds, index of search key found
None, if search fails
"""
found = False
for index in range(len(myTuple)):
if myTuple[index] == key:
found = True
return found, index
return found, None
myTuple = []
numElements = int(input("Enter size of the tuple: "))
print("Enter each element and press enter: ")
for i in range(0, numElements): #tuple input element-wise
num = int(input())
myTuple += (num, )
print("Contents of tuple:", myTuple)
while True:
key = int(input("Enter the number to be searched:"))
found, index = search(myTuple, key)
if found:
print("Element",key," is present in the tuple at index ", index)
else:
print("Element",key," is not present in the tuple")
searchAgain = input("Continue another search? say Y/y for yes, N/n for no:")
if searchAgain != "Y" and searchAgain != "y":
break
Program 17
Write a program that accepts student data, stores it in a dictionary, and then searches for and displays the names of
students who have scored more than 75 marks.
Ans. studentData = {}
def acceptData():
'''
Objective : To input student details
Input Parameter : None
Return Value : None
Practical 431

