python2.7---Query information code

Source: Internet
Author: User

#!/usr/bin/env python                               //program starts #file:  information_service.py#Date: 2016-1-9INFO = {                                             // Define info dictionary          ' user1 ':{                  ' Phone ':     ' 010 ',                  ' Address ':   ' BJ ',                  ' Work ':       'IT '         },         ' user2 ': {                  ' Phone ':      ' 021 ',                  ' Address ':   ' SH ',                  ' work ':      ' OP '          },         ' User3 ':{                  ' Phone ':     ' 020 ',                  ' Address ':   ' GZ ' ,                 ' Work ':      ‘ SL '         },}QUERY = {                                                //definition Query Dictionary          ' Phone ':     ' Call ',         ' Address ':   ' place ',          ' work ':      ' do '}while true:              name = raw_input ("Please input user  you want for infomatin: ")  .strip ()      //.strip () indicates that there can be spaces             while name in info:                 print  "Congratulation, %s  In info list! "  % name     //%s represents a string,% name reference variable                  request = raw_input ("Please input  other infomation:phone (' P ')/address (A)/work (W) ")  .strip ()                   if request ==  ' P '  :  key =  ' Phone '      //if the input is ' P ', assign it to key                 if request ==  ' A '  :  key =  ' Address '                  if request ==  ' W '  : key =  ' work '                 print  '%s ' s %s is % S " %  (Name,query[key],info[name][key])      //Dictionary value value                  break       //query success, jump out of the entire cycle         else:                 choose = raw_input ("Your  Input user ont in info, you can try again,input y/n, try:   ")  .strip ()                  if choose ==  ' Y ':                         continue      //If you want to continue querying, re-cycle  &Nbsp;              else:                          break                              //Program End


This article from "Experience from pain" blog, declined reprint!

python2.7---Query information code

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.