zoukankan      html  css  js  c++  java
  • 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]
    

      

  • 相关阅读:
    (转)Hibernate 注解详解
    PHP - jsPDF+html2canvas实现网页截图导出PDF
    (转)PHP-Sublime Text3插件&快捷键(MAC)
    POI
    maven中使用jstl
    树莓派使用pptpd搭建PPTP服务器
    树莓派网络对时
    Debian 安装 oracle java
    让树莓派(RaspberryPi)显示中文
    树莓派搭建minecraft服务器
  • 原文地址:https://www.cnblogs.com/python-study/p/14059395.html
Copyright © 2011-2022 走看看