Search Name
- Lim Long Teck
- May 11, 2021
- 1 min read
Updated: Jun 24, 2021
Write a Python program to
Declare a list of strings nameList and initialize with the following string elements "Tom", "Joe", "Mary", "John", "Bob", "Jane"
Prompt user to input the name to search and check if the name exists in the list nameList
Display the index of the name list
Program:
nameList = ['Tom','Joe','Mary','John','Bob','Jane']
find = input('Enter name to search: ')
if find in nameList:
print('Name', find, 'is found in position',nameList.index(find),'in the name list.')
else:
print(find, 'not in name list.')
Output:
Enter name to search: John
Name John is found in position 3 in the name list.
Comments