def dialog(): """dialog with user""" phone_book = contacts.PhoneBook() while True: print("""What do you want to do? c - create r - read u - update d - delete q - quit""") action = input("?").lower() if action == 'c': name = input("Input new contact name \n") phone = input("Input the phone \n") phone_book.create(name, phone) elif action == 'r': name = input("Input the contact name \n") print(phone_book.read(name)) elif action == 'u': name = input("Input the contact name \n") phone = input("Input new phone \n") phone_book.update(name, phone) elif action == 'd': name = input("Input the contact name for deleting \n") phone_book.delete(name) elif action == 'q': break
def main(): """main function""" phone_book = contacts.PhoneBook() while True: print("""What do you want to do? c - create r - read u - update d - delete q - quit """) action = input("?").lower() if action == 'q': phone_book.quit() if action == 'c': name = input("Name: ") number = input("Number: ") print(phone_book.create(name, number)) if action == "r": name = input("Name: ") print(phone_book.read(name)) if action == "u": name = input("Name: ") number = input("Number: ") print(phone_book.update(name, number)) if action == "d": name = input("Name: ") print(phone_book.delete(name))
def main(): ''' :return: ''' while True: print("""What do you want to do? c - create r - read u - update d - delete q - quit """) phone_book = contacts.PhoneBook() action = input("?").lower() if action == 'c': name = input("Input name:") number = input("Input number") print(phone_book.create(name, number)) if action == 'r': name = input("Input name:") print(phone_book.read(name)) if action == 'u': name = input("Input name:") number = input("Input number") print(phone_book.update(name, number)) if action == 'd': name = input("Input name:") print(phone_book.delete(name)) if action == 'q': break
def test_create(): """ Test create() option :return: """ pbk = contacts.PhoneBook() pbk.create("Bill", 911) assert pbk.read('Bill') == 911
def test_update(): """ Test update() option :return: """ pbk = contacts.PhoneBook() pbk.create("Bill", 911) pbk.update("Bill", 112) assert pbk.read('Bill') == 112
def test_delete(): """ Test delete option :return: """ pbk = contacts.PhoneBook() pbk.create("Bill", 911) pbk.delete("Bill") with pytest.raises(KeyError): pbk.read('Bill')
def user_interface(): """ Define options :return: """ while True: print("""What do you want to do? c - create r - read u - update d - delete q - quit """) book = contacts.PhoneBook() action = input().lower() if action == 'c': print("Want to add a new contact? Please, print a name: ") name = input("Print name here: ") print("Now, please, fill the number: ") number = input("Print number here: ") book.create(name, number) print('Thank you!') elif action == 'r': print("Find a contact? Please, print a name: ") name = input("Print name here: ") book.read(name) print('Thank you!') elif action == 'u': print("OK. Please, print a contact name to update: ") name = input("Print name here: ") print("Now, please, update the number: ") number = input("Print number here: ") book.update(name, number) print('Thank you!') elif action == 'd': print("Contact is dead? Sorry... Please, print a name to delete: ") name = input("Print name here: ") book.delete(name) print('Thank you!') elif action == 'q': break elif action not in 'crudq': print('There is no such option, please try again!') continue
def interface(): """Phone interface""" phone_book = contacts.PhoneBook() while True: print("""What do you want to do? c - create r - read u - update d - delete q - quit """) funcs = {'c': create, 'r': read, 'u': update} action = input("?").lower() if action == 'q': break funcs.get(action, 'You enter wrong command')(phone_book)
def dialog(): """dialog with user""" phb = contacts.PhoneBook() while True: print("""What do you want to do? c - create r - read u - update d - delete q - quit """) action = input("Choose:").lower() if action == 'q': break if action == 'c': name = input("User name: ") phone = input("User phone: ") phb.create(name, phone) elif action == 'r': try: name = input("User name: ") print(f"Phone number: {phb.read(name)}") except KeyError: print("This name is not present in list\n") elif action == "u": try: name = input("User name: ") phone = input("Phone: ") phb.update(name, phone) except ValueError: print("This name is not present in list\n") else: print("Successful!") elif action == "d": try: name = input("User name: ") phb.delete(name) except ValueError: print("This name is not present in list\n") else: print("Successful!")
"""This script represents communication with program user""" import contacts P_B = contacts.PhoneBook() def ask_to_do(): """Provide list of phonebook action options for user""" print("""What do you want to do? c - create r - read u - update d - delete q - quit """) def confirm_action(text): """Notify user of action executed""" print(text) def main(): """Execute user's commands""" while True: ask_to_do() action = input("?").lower() if action == 'c': name = input("Provide contact name:\n") phone = input("Provide contact phone:\n")
def test_create(): p = contacts.PhoneBook() p.create("Bill", 911) assert p.read('Bill') == 911
def test_delete(): p = contacts.PhoneBook() p.create("Bill", 911) p.delete("Bill") with pytest.raises(KeyError): p.read('Bill')
def test_update(): p = contacts.PhoneBook() p.create("Bill", 911) p.update("Bill", 112) assert p.read('Bill') == 112