Text file data : sponsors.txt file that has stored data with their names and donations
John Smith,230.5
Sally Jones,380
Mary Smith,104.55
David McDougal,165.7
Sally Matthews,184.5
Peter Evans,300.25
Expected Output :
Please enter a search string: Smith
Search returned 2 results:
John Smith,230.5
Mary Smith,104.55
MyCode:
def read_sponsor_data(file_path, word):
with open(file_path, 'r') as file:
content = file.read()
name_count = content.count(list_sponsor)
if word in content:
print('Search returned', name_count, 'results:')
else:
print('Search returned no results.')
for i in range(0, name_count):
print(content)
file.close()
if search_sponsor == 1:
list_sponsor = input("Please enter a search string: ")
read_sponsor_data("sponsors.txt", list_sponsor)
else:
print("Invalid Input")
My Output :
Please enter a search string: Smith
Search returned 2 results:
John Smith,230.5
Sally Jones,380
Mary Smith,104.55
David McDougal,165.7
Sally Matthews,184.5
Peter Evans,300.25
John Smith,230.5
Sally Jones,380
Mary Smith,104.55
David McDougal,165.7
Sally Matthews,184.5
Peter Evans,300.25