精品偷拍一区二区三区,亚洲精品永久 码,亚洲综合日韩精品欧美国产,亚洲国产日韩a在线亚洲

  • <center id="usuqs"></center>
  • 
    
  • 用python編寫“生日悖論”的解決方法

    用python編寫“生日悖論”的解決方法
    that if 23 people are selected at random,there is better than 50% chance that at
    least two of them will have the same birthday (not considering the birth year).
    You are to write a Python function to simulate selecting n people at random
    and checking the probability of having at least two people with the same
    birthday.You should ignore the leap years and assume 365-day years.To be
    more specific,devise a Python function,call it bdp(n,k),that once invoked,will
    select n numbers with replacement from the set of numbers 1 through 365
    inclusive,determine if two or more of the numbers selected are the same (call
    it a hit),and repeat this task k times,and finally return the percentage of the
    hits.Plot your results similar to the graph in the above URL.
    其他人氣:271 ℃時(shí)間:2020-06-02 00:27:36
    優(yōu)質(zhì)解答

    import random

    def bdp(n,k):

    \x09    cv = []

    \x09    for i in range(k):

    \x09\x09        m = []

    \x09\x09        for j in range(n):

    \x09\x09\x09            m.append(random.randint(1,365))

    \x09\x09        counter = 0

    \x09\x09            for k1 in m:

    \x09\x09\x09                for k2 in m:

    \x09\x09\x09\x09                    if k1 == k2:

    \x09\x09\x09\x09\x09                        counter += 1

    \x09\x09        cv.append(float(counter/2)/float(n))

    \x09        ss = 0

    \x09        for i in cv:

    \x09\x09            ss += i

            return ss/float(len(cv))


    親測能用:

    我來回答
    類似推薦
    請使用1024x768 IE6.0或更高版本瀏覽器瀏覽本站點(diǎn),以保證最佳閱讀效果。本頁提供作業(yè)小助手,一起搜作業(yè)以及作業(yè)好幫手最新版!
    版權(quán)所有 CopyRight © 2012-2024 作業(yè)小助手 All Rights Reserved. 手機(jī)版