top of page
  • Pinterest
  • Facebook
  • Instagram

Search Name

  • Writer: Lim Long Teck
    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.

Recent Posts

See All
CountLetters

Write a Python program to - Prompt user to input a sentence - Count the occurrence of each letter in the input sentence - Save the result...

 
 
 
BirthdayParadox

The Birthday Paradox asks the question, “If you asked random people their birthday, how many people do you expect to ask before you find...

 
 
 
ChristmasTree

Write a program to prompt the user for a character and a number, and then print a Christmas tree accordingly. Program: char =...

 
 
 

Comments


bottom of page