#!/usr/bin/env python people = { 'Alice': { 'phone' : '2341', 'addr' : 'Foo drive 23' }, 'Beth': { 'phone' : '9012', 'addr' : 'Bar street 34' }, 'Cecil': { 'phone' : '2344', 'addr' : 'Baz avenue 42' } } labels = { 'phone': 'phone number', 'addr': 'address' } name = raw_input('name: ') request = raw_input('Phone(p) or address(a)?') if request == 'p': key = 'phone' if request == 'a': key = 'addr' if name in people : print "%s's %s is %s." % (name, labels[key], people[name][key]) ~
初级版本十分简陋等学成归来之后写个强大的电话簿,加油↖(^ω^)↗吼吼!!!
转载于:https://blog.51cto.com/hongtengfei/1706945