黑帽联盟

 找回密码
 会员注册
查看: 1721|回复: 0
打印 上一主题 下一主题

[其它] python程序编写数据查询功能-个人原创

[复制链接]

293

主题

18

听众

955

积分

管理员

Rank: 9Rank: 9Rank: 9

  • TA的每日心情
    奋斗
    2023-10-26 13:13
  • 签到天数: 358 天

    [LV.8]以坛为家I

    需求概述:现有一个数据文件contact_list.txt,现在想用python编写一个程序能够交互式的提供用户输入数据来查询想要的东西。

    数据文件内容如下:

    1      WH      IT      12345
    2      GS      CAR     23456
    3      WK      KTV     34567

    4      CC      factory 45678
    5      CXL     SALE    56789


    功能解析(要求):

    1、用户登录进去才可进行数据查询

    实现功能方法:用python设计登录程序

    2、能够交互式输入

    3、对输入相应的数据,返回相应信息

    如果输入的数据信息存在,返回相应数据;如果输入数据信息不存在,也返回相应的提示

    4、输入是quit或exit时,就退出程序。

    5、对存在的bug进行修改,完善程序。

    Bug:没有输入任何数据,或者回车符和空格符,都以输入数据信息不存在处理。



    实现代码:

    #!/usr/bin/python

    while True:
            name = raw_input("please input your name:")

            if name == 'dingwei':
                    password = raw_input("please input your password:")
                    while password != 'cbh':
                            password = raw_input("please input your password:")
                    print "----------------------------------"
                    print "welcome to login to system!"

                    while True:
                            match_yes = 0
                            input = raw_input("please input the name whom you want to search:")
                            contact_file = file('contact_list.txt')
                            while True:
                                    line = contact_file.readline()
                                    if len(line) == 0:break

                                    if input == 'quit' or input == 'exit':
                                            match_yes = 2
                                    if input != "" and input in line:
                                            print 'Match item %s' % line
                                            match_yes = 1
                            if match_yes ==0:
                                    print 'No match item found.'
                            if match_yes ==2:
                                    print '---------------------'
                                    print 'You had exited access!'
                                    break
                    break

            else:
                    print "user %s not found,try again!" % name




    效果截图:

    091723f2x6xsxzumidliix.jpg.thumb.jpg


    相关链接:python语言编写的购物系统
    帖子永久地址: 

    黑帽联盟 - 论坛版权1、本主题所有言论和图片纯属会员个人意见,与本论坛立场无关
    2、本站所有主题由该帖子作者发表,该帖子作者与黑帽联盟享有帖子相关版权
    3、其他单位或个人使用、转载或引用本文时必须同时征得该帖子作者和黑帽联盟的同意
    4、帖子作者须承担一切因本文发表而直接或间接导致的民事或刑事法律责任
    5、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
    6、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
    7、黑帽联盟管理员和版主有权不事先通知发贴者而删除本文

    您需要登录后才可以回帖 登录 | 会员注册

    发布主题 !fastreply! 收藏帖子 返回列表 搜索
    回顶部