Simple select statement and a loop

First, login password [judgment]

   This function is mainly used to achieve while loops and if-else to judge, to achieve a maximum of three unsuccessful tries to exit the program, we should use to achieve lock file processing command.

 ①, program flow

②, the program code of FIG.

③, the program code:

 1 #Write the login interface:
 2 #insert username and password.
 3 #A welcome message is displayed after the authentication is successful.
 4 #Lock the interface after three wrong entries.
 5 username="root"
 6 password='123'
 7 count=0
 8 while count<3:
 9     user=input("Please input username:")
10     passw=input("\nPlease input password:")
11     if user==username and passw==password:
12         print("Welcome!\n")
13         break
14     else:
15         print("Access denied,please try again.\n")
16         count+=1
17 else:
18     print("You have tried three times,Interface locked.\n")

 ④, personal summary:

  Login achieve entry is to enter a user name and password known to match the correct username and password, if the same, it displays the login is successful, failed login error will be credited to the blacklist, the entrance is locked after three, here to that file operations, we can no longer call in the next three or change the password file blacklist file permissions, so the file can not be written to achieve locking of data, when I was writing I did not think of how to bring up the password match, simply write a cycle is incorrectly three times out of the program, did not realize the function of the realization locked.

Second, the three-level menu [design]

    This function is realized also use the loop and the select statement, improve the function or optimized, then the code would use to modify the dictionary or logic, a list of previously stored data that I use, but this logic is somewhat unclear, the general function is achieved.

 ①, flowchart

 ②, the program code of FIG.

 

③, the program code:

. 1  # the Create A Multilevel MENU 
2  # There are in Three Levels The MENU. 
. 3  # by You CAN Turn Enter in each submenu. 
. 4  
. 5 shandong_list = [ ' 1. Jinan ' , ' 2. Tai ' , ' 3. Qingdao ' ]
 6 = jinan_list [ ' long clear zone ' , ' high-tech zone ' , ' area under the calendar ' ]
 . 7 taian_list = [ ' 4. Ningyang ' , ' Dongping ' ]
 8= qingdao_list [ ' Huangdao ' , ' Laoshan ' ]
 . 9 ningyang_list = [ ' Dongshu town ' , ' rural drinking village ' , ' Ciyao town ' ]
 10 B = ' Back ' 
. 11  the while B == ' Back ' :
 12 is      Print (shandong_list)
 13 is      Print ( " . \ nIf there are NO Number in Front of The City, means that IT apos The Last Level of meunu of He " )
 14      A = INPUT ("Please chose one city number:")
15     if a=='1':
16         print(jinan_list)
17     elif a=='3':
18         print(qingdao_list)
19     elif a=='2':
20         while a=='2' or b=='2':
21             b='1'
22             print(taian_list)
23             print("\nIf there are no number in front of the city,it means that's the last level of he meunu.")
24             a =input("\nPlease chose one city number:")
25             if a=='4':
26                 print(ningyang_list)
27                 print("\nThis is the last level,if you want to back please input 2.")
28                 b = input("\nplease input your choose:")
29                 if b=='2':
30                     continue
31                 else:
32                     break
33             else:
34                 print(taian_list)
35                 break
36     else:
37         break
38     print("\nPlease input 'back' return the upside menu or input any other key to quit.")
39     b=input("\nplease input your choose:")
40     if b=='back':
41         continue
42     else:
43         break

④, personal summary

  I also modified in the realization of the three menus several times logic, because there is no clear rationale thinking ahead, the code does not cause a problem but logic often a problem, so before you write a program must design a good process, there is for storing data because the database has not yet learned to call, there is no dictionary to learn, first try to use the list, although reluctantly realized the function, certainly not as good as some of the dictionary to be more rigorous, although each input has reminded before, once on the wrong will launch the program, this is a loophole logic implementation, keep it up.

 

The above two programs are simple to use and if achieved while some of the features, if you can call or use other grammatical program will function better.

 

Guess you like

Origin www.cnblogs.com/Mr-Kitten/p/11780489.html
Recommended