zoukankan      html  css  js  c++  java
  • python小练习

    练习一:
    校验密码是否合法的程序。
    长度5-10位
    密码里面必须包含,大写字母,小写字母和数字
    最多输入5次

    方法一
     1 for i in range(5):
     2     passwd = input('请输入密码:').strip()
     3     if passwd != '':
     4         if len(passwd) >4 and len(passwd<11):
     5             num_count = 0
     6             lower_count = 0
     7             upper_count = 0
     8             for p in passwd:
     9                 if p.isdigit():
    10                     num_count+=1
    11                 elif p.islower():
    12                     lower_count+=1
    13                 elif p.isupper():
    14                     upper_count+=1
    15             if num_count>0 and lower_count>0 and upper_count>0
    16                 print('密码校验通过')
    17             else:
    18                 print('密码不合法')
    19         else:
    20             print('密码最少5位,最长10位')
    21     else:
    22         print('密码不能为空')

    方法二

     1 import string
     2 src_digits = string.digits              #string_数字
     3 src_uppercase = string.ascii_uppercase  #string_大写字母
     4 src_lowercase = string.ascii_lowercase  #string_小写字母
     5 for i in range(5):
     6     passwd=input('请输入密码:').strip()
     7     if len(passwd)>6 and len(passwd)<13:
     8         passwd = set(passwd)
     9         if passwd&set(src_digits) and passwd &set(src_lowercase) and passwd & set(src_uppercase):
    10             passwd = ''.join(passwd)
    11             print('输入密码正确:%s'%passwd)
    12             break
    13         else:
    14             print('输入密码错误')
    15     else:
    16         print('输入的密码不合法')
    17 
    18 else:
    19     print('输入次数过多')

    练习二:

    写一个录入学生作业情况的一个程序
    1、查看学生作业情况
    2、录入学生作业情况
    3、可以让输入3次,需要为空的情况
    homeworks = {
    '张三':
    {'2018.3.22':"未交",'2018.3.23':'wei交'},
    '李四':{'2018.3.22':"未交",'2018.3.23':'wei交'},
    }
    choice = input('请输入:1代表查看学生信息,2代表录入学生作业情况:')
    if choice == '1':
        for k ,v in homeworks.items():
            print('[%s]的作业情况是:%s'%(k,v))
    elif choice == '2':
        for i in range(3):
            name = input('请录入学生姓名:').strip()
            date = input('请输入日期:').strip()
            status = input('请输入状态:').strip()
            if name==''or date==''or status=='':
                print('输入不能为空')
            else:
                if name in homeworks:
                    tmp = {date:status}
                    homeworks[name].update(tmp)
                    print('更新学生信息作业成功')
                else:
                    homeworks[name]={date:status}
                    print('成功')
  • 相关阅读:
    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"
    Tomcat跨域
    Invalid bean definition with name 'dataSource' defined in class path resource [applicationContext.xml]
    网速测试
    程序员实用工具网站
    安装wls报(主清单位置 "/u01/app/oracle/inventory" 无效 (无法读取/写入/执行))
    pom.xml
    CUDA -- 内存分配
    最长上升子序列(LIS: Longest Increasing Subsequence)
    实例化渲染
  • 原文地址:https://www.cnblogs.com/xmhd/p/8708425.html
Copyright © 2011-2022 走看看