Computer Project
Computer Project
names = []
phone_numbers = []
num = 3
for i in range(num):
names.append(name)
phone_numbers.append(phone_number)
print("\nName\t\t\tPhone Number\n")
for i in range(num):
print("{}\t\t\t{}".format(names[i], phone_numbers[i]))
print("Search result:")
if search_term in names:
index = names.index(search_term)
SOURCE CODE
phone_number = phone_numbers[index]
else:
Variables
Input Loop
The loop for i in range(num): runs num times (in this case, 3 times, since num is set
to 3). In each iteration of the loop:
1. The program prompts the user to enter a name using input("Name: ").
2. The program prompts the user to enter a phone number using input("Phone
Number: "). If you wanted to store the phone number as an integer, you could
convert the input using int(input("Phone Number: ")), but in this code, the
phone number is kept as a string.
Search Functionality
After displaying the list, the program asks the user to input a search_term using
input("\nEnter search term: ").
● If the name is found (if search_term in names:), the program retrieves the
corresponding phone number using the index of the found name (index = names.
index(search_term)) and then prints the name and phone number.
SOURCE CODE
● If the name is not found, the program prints "Name Not Found."
Example Workflow
● The user is prompted to enter 3 names and phone numbers.
● The program displays the names and phone numbers entered in a table format.
● The user is then prompted to search for a name.
● The program displays the phone number associated with that name if found, or
"Name Not Found" if the name isn't in the list.
This code provides a basic structure for managing and searching a list of names and phone
numbers in Python.
4o