Python basic exercise, query text content and output;

Source: Internet
Author: User

1. Write the Employee Information table that can be queried by the user:

1). user authentication (enter user name, password)

2). Search Keywords: name

3). Display Id,name,section,phone

4). The Employee Information table reads as follows:

Cat Search_name.txt

001wenlong IT12345678  

002xiaojun IT12345678

003ankang IT12345678

004xiang IT12345678


The script is as follows:

#!/usr/bin/pythonwhile true:            # Into the dead Loop         input = raw_input (' Please input your  username: ')      #交互式输入用户信息, enter input information;         if input ==  "Wenlong":         # Enter this loop if input equals Wenlong (if the user enters Wenlong)                  password = raw_input (' Please input your pass: ')       #交互式信息输入, enter password information;                 p =  ' 123 '                     #设置变量P赋值为123                  while password != p:          #如果输入的password   Not equal to P (123),  into the loop                          password = raw_input (' Please input  your pass again: ')      #交互式信息输入, enter password information;                 if password == p:          #如果password等于p (123), enter this loop                          print  ' welcome to select system! '                #输出提示信息;                         while true:             #进入循环;                                 match =  0      #设置变量match等于0;                                  input = raw_input ("Please input the name whom  you want to search : ")     #交互式信息输入, enter input information;                                  while not input.strip ():     #判断input值是否为空, if the input output is empty, enterCyclic;                                          input = raw_input ("Please input the name whom  you want to search : ")          #交互式信息输入, Enter input information;                                 name_file  = file (' search_name.txt ')       #设置变量name_file, file (' Search_name.txt ') is to invoke the document named Search_name.txt                                   while true:                #进入循环;                                          line =  Name_file.readline ()             #以行的形式, read Search_ Name.txt Document Information;                                          if len (line)  == 0:       #当len (Name_file.readline ()  ) is 0 o'clock, indicating that the file has been read, Len (Name_file.readline ()  ) is the character length of each line, and the contents of the blank line are \ n and two characters. Len is 0 o'clock into the loop;                                                   break        #执行到这里跳出循环;                                           if input in line:     #如果输入的input信息可以匹配到文件的某一行, into the cycle;                                                   print  ' match item: %s '   %line      #输出匹配到的行信息;                                                  match  = 1     #给变量match赋值为1                                   if match == 0 :                #如果match等于0, then enter    ;                                          print   ' no match item found! '           #输出提示信息;         else: print  "sorry ,user  %s not found "  %input        #如果输入的用户不是wenlong, the output information does not have this user;



The above script because adds the note, the direct copy cannot use, here re-paste once;

#!/usr/bin/pythonwhile true:        input = raw_input (' Please input your username: ')         if input  ==  "Wenlong":                 password = raw_input (' Please input your pass: ')                  p =  ' 123 '                  while password !=  p:                         password = raw_input (' please input your  Pass again: ')                  if password == p:                         print  ' welcome to select system! '                          while True:                                  match = 0                                  input = raw_input ("Please input the name whom you  want to search : ")                                  while not  Input.strip ():                                          print  ' no match item found! '                                           input = raw_input ("Please input the name whom you  want to search : ")                                   name_file = file (' Search_name.TXT ')                                  while true:                                           line = name_file.readline ()                                           if len (line)  ==  0:                                                   break                                          if input in  line:                                                  print  ' match  item:  '   , line                                                   match = 1                                 if match == 0 :                                           print  ' no match item found! '         else: print  "Sorry ,user  %s not  found  " %input

Test Picture:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/70/1F/wKioL1WyAMriK2GcAAEZHZd0MPY639.jpg "title=" python _test.png "alt=" Wkiol1wyamrik2gcaaezhzd0mpy639.jpg "/>

This article is from the "obsessed" blog, make sure to keep this source http://dragondragon.blog.51cto.com/6170889/1678122

Python basic exercise, query text content and output;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.