Chinaunix

标题: python [打印本页]

作者: linuxccc    时间: 2009-09-02 16:30
标题: python
#!/urs/bin/python



contact = {}
contact_list = []
select = ['1.insert','2.delete']
for i in select:
        print i
print 'what\'s your choise:'
get = raw_input('1 or 2')

if get == 1:
        test = 1
        while test==1:
                contact['name'] = raw_input("please input name: ")
                contact['phone'] = raw_input("please input phone number: ")
                contact_list.append(contact.copy())
                go_on = raw_input("continue?\n")
                    if go_on == "yes":
                        pass
                    elif go_on == "no":
                        break
                        test = 0
                    else:
                        print "you didn't say no\n"

elif get == 2:
        test = 1
        while test == 1:
                num = raw_input("what's num do you want to delete:")
                for contact in contact_list:
                        print "%d: name=%s" % (num, contact['name'])
                        print "%d: phone=%s" % (num, contact['phone'])
                answer = raw_input('do you want to delete the message? y/n')
                if answer == y:
                        for i in contact_list:
                                if i == num:
                                        contact_list.remove(i)
                                        break
                                        test = 0
                else : pass

else :
        print 'again'


i = 1
for contact in contact_list:
    print "%d: name=%s" % (i, contact['name'])
    print "%d: phone=%s" % (i, contact['phone'])
    i = i + 1
作者: linuxccc    时间: 2009-09-02 16:31
这是小弟刚整理出来的程序, 可是执行之后却发现这么个结果

1.insert
2.delete
what's your choise:
1 or 21
again
作者: linuxccc    时间: 2009-09-02 16:32
请高手指点,让程序能够记录以及删除 姓名及号码




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2