今天写了两个程序代码,一个是用户登录,一个是三级菜单的:

用户登录:

#!/usr/bin/env python
#Author: Tony Cabel

import os
import tab

users = [['xuande','123'],['mengde','qwe'],['zhongmou','123qwe']] 


for i in range(3):
    name = input("Account: ")
    pas  = input("Password: ")
    if [name,pas] in users:
        print('Account success. Welcome %s!'%name)
        break
    else:
        ism = 2 - i
        print("Invalid name or password. Please retry and left %s time"%ism)
        if i == 2:
            print("You lost there times. account is locked now")
        continue

  

三级菜单:

 1 #!/usr/bin/env python
 2 #-*- coding:utf-8 -*-
 3 #Author: Tony Cabel
 4 
 5 menus = {
 6     '山东':{'德州':['陵县','乐陵','宁津','齐河','武城','禹城'],
 7                 '济南':['天桥','历下','槐荫','历城','宋官庄'],
 8                 '东营':['河口','利津','东城','西城']},
 9     '北京':{'朝阳':['金台路','双井','劲松','宋家庄'],
10                '昌平':['天通苑','沙河','回龙观','龙泽'],
11                '西城':['宣武门','复兴门','长椿街'],
12                '海淀':['西二旗','五道口','上地','知春里']}
13 }
14 
15 flag = False
16 
17 while not flag:
18     for item in enumerate(list(menus.keys())):
19         index = item[0]
20         pro = item[1]
21         print(index,pro)
22     print("Press 'e' to exit the program.")
23     men = input("Which province do you select (press the before number)? ")
24     if men.isdigit() and int(men) < len(menus):
25         men1 = int(men)
26         name = menus.keys()
27         prov = list(menus.keys())[men1]
28         while not flag:
29             for items in enumerate(menus[prov]):
30                 ind = items[0]
31                 cit = items[1]
32                 print(ind,cit)
33             print("Press the number to enter the next menu and press 'q' to quit the last menu.")
34             cit_num = input("Which city do you select (press the before number)? ")
35             if cit_num.isdigit() and int(cit_num) < len(list(menus[prov].keys())):
36                 cit_num1 = int(cit_num)
37                 city = menus[prov].keys()
38                 coun = list(menus[prov].keys())[cit_num1]
39                 while not flag:
40                     for i in list(menus[prov][coun]):
41                         print(i)
42                     flo = input("Press 'q' to quit the last menu and press 'e' to exit the program.")
43                     if flo == 'q':
44                         break
45                     elif flo == 'e':
46                         exit("Good Bye".center(50,'-'))
47                     else:
48                         print("Please input according to the introduction.")
49                         continue
50             elif cit_num == 'q':
51                 break
52             else:
53                 print("Please input according to the introduction.")
54                 continue
55     elif men == 'e':
56         exit("Good Bye".center(50,'-'))
57     else:
58         print("Please input according to the introduction.")
59         continue

 

posted on 2016-11-22 16:48  自然洒脱  阅读(221)  评论(0编辑  收藏  举报