#!/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