• python练习题二


    1、计算成绩

    scores = {"baidu":32,"google":78,"weixin":95,"facebook":68,"aws":94,"ali":97}
    for k,v in scores.items():
        if(v == max(scores.values())):
            print(k,v)
    
    for k,v in scores.items():
        if(v == min(scores.values())):
            print(k,v)
    so = []       
    for v in scores.values():
        so.append(v)
        
    avg = sum(so)*1.0/len(so)
    print(round(avg,2))
    
    ali 97
    baidu 32
    77.33
    

      

    2、找素数

    import random
    notprime = []
    prime = []
    li = [random.randint(1,99) for i in range(100)]
    print("List numbers are: ",li)
    for i in range(len(li)):
        for j in range(2,li[i]-1):
            if (li[i]%j != 0):
                continue
            else:
                notprime.append(li[i])
                break
    #print(notprime)
    prime = set(li) - set(notprime)
    print("Prime numbers are: ",list(prime))
    
    List numbers are:  [60, 63, 88, 66, 30, 99, 63, 51, 35, 18, 48, 90, 21, 28, 3, 63, 68, 89, 96, 42, 32, 1, 25, 42, 56, 97, 20, 90, 86, 21, 1, 79, 97, 44, 54, 66, 77, 62, 98, 70, 37, 38, 82, 24, 17, 54, 42, 92, 6, 55, 72, 1, 93, 25, 97, 72, 8, 2, 27, 45, 48, 51, 82, 25, 55, 76, 53, 26, 34, 53, 9, 45, 13, 91, 44, 62, 59, 75, 58, 46, 51, 45, 44, 38, 20, 37, 30, 83, 34, 73, 48, 68, 50, 75, 93, 60, 77, 71, 61, 52]
    Prime numbers are:  [1, 2, 3, 97, 37, 71, 73, 13, 79, 17, 83, 53, 89, 59, 61]
    

      

  • 相关阅读:
    libgdx的环境搭建2022版 浮云
    MAC 升级npm版本
    网站测试工具
    Win7系统下安装IIS
    测试中的"黑天鹅"
    虚拟机的三种连接方式
    MySQL show create table
    蓝屏死机判断
    javascript 字符串处理全攻略
    WPF入门介绍 1
  • 原文地址:https://www.cnblogs.com/python-study/p/14059395.html
Copyright © 2020-2023  润新知