zoukankan      html  css  js  c++  java
  • day 08 作业

    '''1. 有如下值集合 [11,22,33,44,55,66,77,88,99,90...],
    将所有大于 66 的值保存至字典的第一个key中,将小于 66 的值保存至第二个key的值中
    
    即: {'k1': 大于66的所有值, 'k2': 小于66的所有值}'''
    
    i=[11,22,33,44,55,66,77,88,99]
    k1=[]
    k2=[]
    for l in i :
        if l>66:
            k1.append(l)
        elif l<66 :
            k2.append(l)
    lis={'k1':k1,'k2':k2}
    print(lis)
    
    

    2.223

    # 2. 统计s='hello alex alex say hello sb sb'中每个单词的个数
    #
    # 结果如:{'hello': 2, 'alex': 2, 'say': 1, 'sb': 2}
    
    s='hello alex alex say hello sb sb'
    hello=s.count('hello')
    alex=s.count('alex')
    say=s.count('say')
    sb=s.count('sb')
    print({'hello':hello,'alex':alex,'say':say,'sb':sb})
    
    
    # 2. 统计s='hello alex alex say hello sb sb'中每个单词的个数
    #
    # 结果如:{'hello': 2, 'alex': 2, 'say': 1, 'sb': 2}
    
    s='hello alex alex say hello sb sb'
    hello=s.count('hello')
    alex=s.count('alex')
    say=s.count('say')
    sb=s.count('sb')
    print({'hello':hello,'alex':alex,'say':say,'sb':sb})
    
    
    # 2. 统计s='hello alex alex say hello sb sb'中每个单词的个数
    #
    # 结果如:{'hello': 2, 'alex': 2, 'say': 1, 'sb': 2}
    
    s='hello alex alex say hello sb sb'
    hello=s.count('hello')
    alex=s.count('alex')
    say=s.count('say')
    sb=s.count('sb')
    print({'hello':hello,'alex':alex,'say':say,'sb':sb})
    
    
    . 假设有一个文件test.txt,内有如下内容
    # l=[
    #     {'name':'alex','age':84},
    #     {'name':'oldboy','age':73},
    #     {'name':'egon','age':18},
    # ]
    # 需求:
    # 1. 读取文件内容
    # 2. 计算这三个人的年龄总和
    with open(
        r'D:pycharm项目练习第一周作业题	est.txt')as f:
        data=f.read()
        # print(data)
    l = [{'name': 'alex', 'age': 84}, {'name': 'oldboy', 'age': 73}, {'name': 'egon', 'age': 18} ]
    alex_age=l[0]['age']
    oldboy_age=l[1]['age']
    egon_age=l[2]['age']
    sum_age=alex_age+oldboy_age+egon_age
    print(sum_age)
    
  • 相关阅读:
    js事件循环机制event-loop
    javascript编译与执行
    css中rem,em,px的区别和使用场景
    float
    flex布局
    azoux's blog
    1004 成绩排名 PAT Basic Level
    1003 我要通过! PTA Basic Level
    腾讯云防盗链测试
    简单多项式求解
  • 原文地址:https://www.cnblogs.com/fwzzz/p/11448760.html
Copyright © 2011-2022 走看看