• day13 考试练习


    1,有两个列表
    l1 = [11,22,33]
    l2 = [22,33,44]
    a. 获取内容相同的元素列表
    b. 获取 l1 中有, l2 中没有的元素列表
    c. 获取 l2 中有, l1 中没有的元素列表
    d. 获取 l1 和 l2 中内容都不同的元素

    a,获取内容相同的元素列表
    l1 = [11,22,33] l2 = [22,33,44] for i in l2: if i in l1: print(i)

    结果:
    22
    33
    l1  =  [11,22,33]
    l2 = [22,33,44]
    for i in l1:
    if i not in l2:
    print(i)

    结果:
    11
    l1    =    [11,22,33]
    l2    =    [22,33,44]
    for i in l2:
        if i not in l1:
            print(i)

    结果:
    44
    l1    =    [11,22,33]
    l2    =    [22,33,44]
    for i in l2:
        if i not in l1:
            print(i)
    for i in l1:
        if i not in l2:
            print(i)

    结果:
    44
    11

    17,有1 2 3 4 5 6 7 8   8个数字,能组成多少个互不相同且无重复数字的两位数? 

    count =0
    for i in range(1, 9):
        for v in range(1, 9):
            if i !=v:
                count += 1
    print(count)

    18、99乘法表

    for i in range(1,10):
        string = ""
        for j in range(1,i+1):
            string +=str(j) + " * "+str(i) + " = " +str(i*j)+"	"
        print(string)

    20 用python 开发程序自动计算方案

    公鸡5文钱一只,母鸡3文钱一只,小鸡3只一文钱,用100文钱买100只鸡,其中公鸡,母鸡,小鸡都必须要有,文公鸡,母鸡,小鸡要买多少只刚好凑足100文钱

    for x in range(1,100//5):
        for y in range(1,100//3):
            for z in range(1,100):
                if x + y + z == 100 and 5*x + 3*y + z/3 == 100:
                    print(x,y,z)

    1,请用代码实现:利用下划线将列表的每一个元素拼接成字符串,

    li = ['alex','eric','rain']

    li = ['alex','eric','rain']
    s = "_".join(li)
    print(s)


    alex_eric_rain

    5,写代码,有如下元组,按照要求实现每一个功能

    tu = ('alex','eric','rain')

    a,计算元组长度并输出

    b,获取元组的第2个元素,并输出

    tu = ('alex', 'eric', 'rain')
    # print(len(tu))
    # print(tu[2])
    # print(tu[1:])
    # #step 为正
    # print(tu[1:90])
    # for elem in tu:
    #     print(elem)
    # for idx in range(len(tu)):
    #     print(idx)
    
    # for idx, elem in enumerate(tu, 10):     enumerate
    #     print(idx, elem)

    6,

    tu =(
         "alex",     [         11,         22,         {             "k1":'v1',             "k2":["age","name"],             "k3":(11,22,33)         },         44     ] ) tu[1][2]["k2"].append("")

    12,

    19题

    nums = [2,7,11,15,1,8,7]
    a =[]
    for i in range(len(nums)):
        for j in range(len(nums)):
            if nums[i] + nums[j] ==9:
                a.append((i,j,))
    print(a)

    3,

    li = ["sdsdsd"]
    print (len(li))
    li.append("dsad")
    li.insert(0,"dsad")
    li.remove("eric")
    v = li.pop(1)
    print(li,v)




    v = li.reverse()
    for i in range(len(li)):
    print(i)
    for i,q in enumerate(li,100):
    print(i,q)
    for i in li:
    print(i)

    16,

    user_list = [
    ]
    for i in range(1,302):
        temp = {'name': 'alex'+str(i), 'email': 'alex@lve.com' + str(i), 'pwd': 'pwd'+str(i)}
        user_list.append(temp)
    
    while True:
        # 每页显示10条数据
        s = input("请输入1,2,3-31页码:")
        s = int(s)
        # user_list[0,10]  1
        # user_list[10,20]  2
        # user_list[20,30]  3
        start = (s-1) * 10
        end = s * 10
        result = user_list[start: end]
        for item in result:
            print(item,type(item))
  • 相关阅读:
    elasticsearch 事务日志 sync 都干了些什么?
    elasticsearch 事务日志是个啥东西?
    elasticsearch 分片恢复经历了哪些步骤?
    定向爬取网页内容
    文件查询之三:文件和目录的批量操作
    文件查询之二:文件属性查询
    文件查询之一:文件名和文件后缀查询
    记一次SQL联合查询注入工具的编写
    线程间使用socket通信的计算器
    简单的远程加解密文件
  • 原文地址:https://www.cnblogs.com/xiaomai-rhce/p/10116911.html
Copyright © 2020-2023  润新知