Advertisement
Talithacelin

Contact book

Dec 20th, 2022 (edited)
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.65 KB | None | 0 0
  1. #contactnumber
  2. import time
  3. import sys
  4.  
  5. def start():
  6.     names =[]
  7.     phone_nums = []
  8.     num = 1
  9.  
  10.     user = input("Enter your name: ")
  11.     print(f"Hello {user}. Let's make a contact book! ")
  12.                
  13.     while True:
  14.         name = input("Add a name: ")
  15.         phone_num = input("Enter the phone number: ")
  16.         names.append(name)
  17.         phone_nums.append(phone_num)
  18.  
  19.         again = input("Add another? : (y/t)")
  20.         if again == "y":
  21.             print()
  22.             num += 1
  23.             continue
  24.  
  25.         else:
  26.             print(f"\n---- {user}'s CONTACT BOOK ----")
  27.             print("Name\t\t\tPhone Number")
  28.             for i in range(num):
  29.                 print(f"{i+1}. {names[i]}\t\t\t{phone_nums[i]}")
  30.             print()
  31.  
  32.         search = input("Enter name to search: ")
  33.         time.sleep(0.7)
  34.         if search in names:
  35.             index = names.index(search)
  36.             phone_num = phone_nums[index]
  37.             print(20*'-')
  38.             print("Result: ")
  39.             print(f"Name: {search} | Phone Number: {phone_num}")
  40.             print(20*"-")
  41.             print("1 Add another contact\n2 Reset\n3 Exit")
  42.             ask = input("Choose an option: ")
  43.             if ask == "2" :
  44.                 start()
  45.  
  46.             elif ask == "1":
  47.                 num += 1
  48.                 continue
  49.            
  50.             else:
  51.                 print("BYE")
  52.                 sys.exit()
  53.                
  54.         else:
  55.             print("Name not found..")
  56.             print("1 Add another contact\n2 Reset\n3 Exit\n4 Try again ")
  57.             ask = input("Choose an option: ")
  58.             if ask == "2" :
  59.                 start()
  60.  
  61.             elif ask == "1":
  62.                 num += 1
  63.                 continue
  64.  
  65.             elif ask == "4":
  66.                 search = input("Enter name to search: ")
  67.                 time.sleep(0.7)
  68.                 if search in names:
  69.                     index = names.index(search)
  70.                     phone_num = phone_nums[index]
  71.                     print(20*'-')
  72.                     print("Result: ")
  73.                     print(f"Name: {search} | Phone Number: {phone_num}")
  74.                     print(20*"-")
  75.                     print("1 Add another contact\n2 Reset\n3 Exit")
  76.                     ask = input("Choose an option: ")
  77.                 if ask == "2" :
  78.                     start()
  79.  
  80.                 elif ask == "1":
  81.                     num += 1
  82.                     continue
  83.            
  84.                 else:
  85.                     print("BYE")
  86.                     sys.exit()
  87.             else:
  88.                 print("BYE")
  89.                 sys.exit()
  90.        
  91. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement