zoukankan      html  css  js  c++  java
  • python第11天作业

    #、写函数,计算传入字符串中【数字】、【字母】、【空格] 以及 【其他】的个数
    def count(s):
    nu,st,sp,it = 0,0,0,0

    for i in s:
    if i.isdigit():
    nu += 1
    elif i.isalpha():
    st += 1
    elif i.isspace():
    sp += 1
    else:it += 1
    print('在字符串%s中 数字有33[45m%s33[0m个
    字母有33[44m%s33[0m个 空格有33[45m%s33[0m个
    其他有33[45m%s33[0m个 ' % (s,nu,st,sp,it))
    s = input('请输入字符串:')
    count(s)

    #写函数,判断用户传入的对象(字符串、列表、元组)长度是否大于5
    def cmlen(*args):
    print(args)
    for i in args:
    if len(i) > 5:print(i,'的长度大于5')
    else:print(i,'长度小于等于5')
    l = [1,2,3,4,5,6,7,8,9,0]
    m = (1,2,3,4)
    s = 'dfxffdfdgdsfdsf'
    cmlen(l,m,s)

    #写函数,检查传入列表的长度,如果大于2,那么仅保留前两个长度的内容,并将新内容返回给调用者
    def listcut(l):
    if type(l) is list:
    if len(l) >2:
    return l[:2]
    else:return l
    else:print('参数错误,应传入列表')
    l = [1]
    print(listcut(l))

    #写函数,检查获取传入列表或元组对象的所有奇数位索引对应的元素,并将其作为新列表返回给调用者
    def checklist(l):
    if (type(l) is list or type(l) is tuple) and len(l) != 0:
    return list(l[1::2])
    else:print('请输入至少有两个元素的列表或元组')
    l = [1,2]
    print(checklist(l))
  • 相关阅读:
    java.util.Dictionary源码分析
    java.util.HashMap源码分析
    公钥密码与数字签名
    迭代器模式(Iterator Pattern)
    EIGamal密码体制
    RSA安全性问题
    观察者模式(Observer Pattern)
    不对称密钥密码体系之RSA
    大道至简第七章读后感
    产生随机数
  • 原文地址:https://www.cnblogs.com/fenglin0826/p/7235435.html
Copyright © 2011-2022 走看看