首页 > 编程语言 > 详细

python中字典的练习

时间:2015-11-21 14:32:41      阅读:239      评论:0      收藏:0      [点我收藏+]

源代码如下:

#!/usr/bin/env python

#Filename:addressbook.py


adbook={‘alice‘:100,‘bob‘:101,‘chanel‘:102}

while True:

    choice=raw_input("Please input l:list,f:find numuber,e:exit the program: ")

    if  choice == ‘l‘:

        print "The addressbook is %s" % adbook

    elif choice == ‘f‘:

        name=raw_input("Please input you name: ")

        if name in adbook:

            phone=adbook[name]

            print "the %s phonenum is %s" %(name,phone)

        else:

            print "Please input the right name"

    elif choice == ‘e‘:

        break

    else:

        print "Please input l or f"


说明:此程序耗时一个多小时,但还是不够好,感觉逻辑有点混乱,求指教。


本文出自 “不再犹豫” 博客,请务必保留此出处http://fangyuan2015.blog.51cto.com/3845944/1715374

python中字典的练习

原文:http://fangyuan2015.blog.51cto.com/3845944/1715374

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!