鱼C论坛

 找回密码
 立即注册

【Python学习笔记】建立通讯录

已有 462 次阅读2016-12-23 22:42 | Python

def initInfo():
    info = {'Cao':'021-43333333',\
            'Kobe':'021-98888888',\
            'Harry':'021-3467890'}
    return info

def searchInfo(InfoList):
    Name = raw_input('Please search the name:')
    if Name in InfoList.keys():
        print 'The phone number is',InfoList[Name],'\n'
    else:
        print 'The name isn\'t exsist\n' 

def insertInfo(InfoList):
    Name = raw_input('Please add the name:')
    if Name in InfoList.keys():
        print 'The name is exist\n'
    else:
        Phone = raw_input('Please add the phone number:')
        InfoList[Name] = Phone
        print '\n'

def deleteInfo(InfoList):
    Name = raw_input('Please input the name:')
    del InfoList[Name]
    print '\n'

def exitSystem():
    print 'Thank you for your use\n'

print '|---Welcome To the System---|'
print '|---1: Search for one\'s information ---|'
print '|---2: Insert New information ---|'
print '|---3: Delete one\'s information ---|'
print '|---4: Exit the System ---|'
info = initInfo()
sysCommand = {'1':searchInfo,'2':insertInfo,'3':deleteInfo}
command = raw_input('Please input the command:')
while(command != '4'):
    sysCommand[command](info)
    command = raw_input('Please input the command:')
exitSystem()

    

路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-6 18:06

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

返回顶部