zoukankan      html  css  js  c++  java
  • 打印三级菜单,打印文件最后一行

    1、用户交互,显示省市县三级联动的选择

    dic = {
        "河北": {
            "石家庄": ["鹿泉", "藁城", "元氏"],
            "邯郸": ["永年", "涉县", "磁县"],
        }
        "河南": {
            ...
        }
        "山西": {
            ...
        }
     
    }
    #!/usr/bin/env python
    # coding:utf-8
    dic = {
        "河北": {
            "石家庄": ["鹿泉", "藁城", "元氏"],
            "邯郸": ["永年", "涉县", "磁县"],
        },
        "河南": {
            ...
        },
        "山西": {
            ...
        }
    
    }
    print(type(dic))
    def  threedic(dict):
        while True:
            for i  in dict:             #河北  河南   山西              石家庄邯郸
                print(i)
            key=input("》》》: ").strip()   # 河北
            if key == 'b' or key == 'q':
                return key
            if type(dict) == list:
                continue
            else :
                if  key in dict.keys()  and dict[key]  :
                    ret = threedic(dict[key])         #  河北的  值   石家庄   邯郸
                    if ret == 'q':
                        return ret
                    continue
                elif  not dict.get(key)  or  not dict[key] :
                    continue
    
    threedic(dic)
     

    2.打印出一个文件的最后一行
    def last():
        f=open('test.py','rb')
        offs=-10
        while True :
            res=[]
            f.seek(offs,2)
            a=f.readlines()
            for i  in  a :
                res.append(i)
                if len(res)>1 :
                    print("文件的最后一行是:  %s" %((res[-1]).decode('utf-8')))
                    exit()
                else :
                    offs*=2
    lsat()

     3、统计字符串中大小写字母,数字出现的个数,并以字典方式打印出来

    def  tongji(x):
        a=b=c=0
        for  i  in x:
            if   i>='a'  and i<= 'z':
               a+=1
            if  i>='A'  and  i <='Z' :
                b+=1
            if  i>='0' and i<='9':
                c+=1
        list1=['大写字母','小写字母','数字']
        list2=[a,b,c]
        dict(zip(list1,list2))
        print (dict(zip(list1,list2)))
    tongji('A12345asdasd')

    I can feel you forgetting me。。 有一种默契叫做我不理你,你就不理我

  • 相关阅读:
    酒店预订2
    酒店预订1
    软件2
    酒店预定系统
    系统软件构成
    用例图
    软件构成
    业务用例名
    业务用例结果查询
    业务用例导师交流
  • 原文地址:https://www.cnblogs.com/weidaijie/p/9660961.html
Copyright © 2011-2022 走看看