simeonshopov

Phone book

May 20th, 2020
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. contacts = {}
  2. count = None
  3.  
  4. while True:
  5.     info = input()
  6.     if info.isdigit():
  7.         count = int(info)
  8.         break
  9.     if info == 'search':
  10.         break
  11.     name, number = info.split('-')
  12.     if name and number:
  13.         contacts[name] = number
  14.  
  15. if count:
  16.     for x in range(count):
  17.         contact = input()
  18.         if contact in contacts:
  19.             print(f'{contact} -> {contacts[contact]}')
  20.         else:
  21.             print(f'Contact {contact} does not exist.')
  22. else:
  23.     while True:
  24.         info = input()
  25.         if info == 'stop':
  26.             break
  27.         name = info
  28.         if name in contacts:
  29.             print(f'{name} -> {contacts[name]}')
  30.         else:
  31.             print(f'Contact {name} does not exist.')
Advertisement
Add Comment
Please, Sign In to add comment