Python Learning-Dictionary exercises: simple Address Book

Source: Internet
Author: User

Functional Requirements:

    • Query contact, enter the name, you can query the current contacts in the contact information, if the contact exists, the output contact information, if not exist, then inform
    • Insert a contact, you can create a new contact in the contacts, if the contact already exists, ask whether to modify the contact information, if it does not exist, create a new contact
    • Delete a contact, you can delete the contact, if the contact does not exist, tell
    • Enter a command to exit contacts

Specific code implementation:

1 #!/usr/bin/env Python32 #-*-coding:utf-8-*-3 #@Time: 2018/3/26 10:014 #@Author: Yang5 #@File: exercise.py6 #@Software: Pycharm7 8 #Contacts9 Print(" "|---Welcome to the Address Book---|Ten |---1, contact information---| One |---2, insert a new contact---| A |---3, delete contact information---| - |---4, exit Address Book Program---| - " ") theAddressBook = {'Xiao Yang': 12345678,'Xiao Zhang': 12345679,'Xiao Zhao': 12345670} -  while1: -Order_code = input ('Please enter the instruction code:') -     ifOrder_code.isdigit () = = False:#determine if the instruction is composed of only numbers +         Print('The instruction code you entered is malformed, please re-enter it as prompted! ') -         Continue +item = Int (Order_code)#converting an input instruction to an integral type A  at     ifitem = = 4: -         Print('thanks for using the Address Book! ') -          Break      #End Loop -     #Enter the name of the contact person -Name = input ('Please enter the name of the contact person:') -     ifitem = = 1:#Query Contact Information in         ifNameinchAddressBook: -             Print(Name,':', Addressbook[name]) to             Continue     #End Current Loop +         Else: -             Print('The contact does not exist. ') the     ifitem = = 2:#New contact Person *         ifNameinchAddressBook: $             Print('the contact you entered already exists in the Address book--->>', Name,':', Addressbook[name])Panax NotoginsengIs_edit = input ('Whether you need to modify the contact information: (y/n)')#determine if you need to modify the current contact information -             ifIs_edit = ='Y': theUserphone = input ('Please enter contact Phone:') +Addressbook[name] =Userphone A                 Print(AddressBook) the                 Continue +             Else: -                 Continue $         Else: $Userphone = input ('Please enter contact Phone:') -addressbook[name]=Userphone -             Print('Contact added successfully! ') the             Print(AddressBook) -             ContinueWuyi     ifitem = = 3:#Delete a contact the         ifNameinchAddressBook: -             delAddressbook[name] Wu             Print('Contacts deleted successfully! ') -             Print(AddressBook) About             Continue $         Else: -             Print('contact does not exist.')

Python Learning-Dictionary exercises: simple Address Book

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.