جزيت خيرًا.
قمت بتطبيق ما ذكرته .. هذا الكود كالتالي :
phone_numbers = ["1111111111", "2222222222", "3333333333", "4444444444", "5555555555", "6666666666", "7777777777"]
names = ["amal", "Mohammed", "Khadijah", "Abdullah", "Rawan", "Faisal", "Layla"]
def search_by_phone_number(phone_number):
while len(phone_number) != 10 or not phone_number.isnumeric():
print("This is invalid number")
phone_number = input("enter phone number: ")
if phone_number not in phone_numbers:
print("Sorry, the number is not found")
else:
print(names[phone_numbers.index(phone_number)])
def search_by_name(name):
if name not in names:
print("Sorry, the name is not found")
else:
print(phone_numbers[names.index(name)])
def add_user(username, user_phone_number):
while username in names or user_phone_number in phone_numbers:
print("this name or phone number is already exists")
username = input("enter name: ")
user_phone_number = input("enter phone number: ")
phone_numbers.append(user_phone_number)
names.append(username)
print("if you want to search write \"s\"\nif you want to add write \"a\"\nif you want to quit write \"q\"")
want = input("I want to: ")
while want != "q":
if want == "s":
print(
"if you want to search by phone number write \"p\"\nif you want to search by name write \"n\"\nif you want to quit write \"q\"")
want = input("I want to: ")
if want == "p":
search_by_phone_number(input("enter phone number: "))
elif want == "n":
search_by_name(input("enter name: "))
elif want == "q":
break
else:
print("write p or n \nplease try again")
elif want == "a":
add_user(input("enter name: "), input("enter phone number: "))
else:
print("write s or a \nplease try again")
want = input("I want to: ")
'''
if want == "s":
print("if you want to search by phone number write \"p\"\nif you want to search by name write \"n\"\nif you want to quit write \"q\"")
want = input("I want to: ")
if want == "p":
search_by_phone_number(input("enter phone number: "))
elif want == "n":
search_by_name(input("enter name: "))
else:
print("write p or n \nplease try again")
elif want == "a":
add_user(input("enter name: "), input("enter phone number: "))
else:
print("write s or a \nplease try again")
'''