在这个Python代码中,year=[0]*365是什么意思?

在这个Python代码中,year=[0]*365是什么意思?,python,function,random,probability,birthday-paradox,Python,Function,Random,Probability,Birthday Paradox,我试着写一个“生日悖论”的函数。 我在互联网上找到了一些例子,并成功地将所有内容结合在一起,进行了一些修改,但在我的程序中仍然有一些我不理解的地方 这是我的节目: # The Birthday Paradox print "If there are 23 students in your class, what are the chances that another student and you will have birthday in the same day?" print "" p

我试着写一个“生日悖论”的函数。 我在互联网上找到了一些例子,并成功地将所有内容结合在一起,进行了一些修改,但在我的程序中仍然有一些我不理解的地方

这是我的节目:

# The Birthday Paradox

print "If there are 23 students in your class, what are the chances that another student and you will have birthday in the same day?"
print ""
print "Use the function has_duplicates(numExamples) to check it out!"
print "Please write in (numExamples) the number of examples of different lists of birthdays of 23-students-classes you want to check."

def has_duplicates(numExamples):

import random
probability = float()

for example in range(numExamples):
   year = [0]*365
   print year
   foundprobability = False
   for i in range(23):
       birthday = random.randrange(365)
       year[birthday] = year[birthday] + 1
       if year[birthday]>1:
          foundprobability = True

   if foundprobability == True:
       probability = probability + 1

countprobabilty = float(probability/numExamples)
print "The probability of a shared birthday in", numExamples,
print "examples of different lists of birthdays of 23-students-classes is", countprobabilty
我不明白这句话的意思:

year = [0]*365
我为什么想要这样一个列表[0,0,0,0…]?

谢谢大家!! 内塔,
生物学学生创建一个包含365个值为0的元素的列表:
[0,0,0,0…]

生日=随机。随机范围(365)
创建一个从0到365的列表,并选择一个随机元素。

请参见

,因为该算法要求一年365天中的每一天都有一个计数器,如下所示:

   year[birthday] = year[birthday] + 1
要使
年[生日]
出现在此语句中,必须事先对其进行初始化,并且

    year = [0] * 365

初始化它。

year=[0]*365
创建了一个包含365个值为0的元素的列表:
[0,0,0…]
我知道,但为什么要创建这样的列表?可能是重复的,因为您实际上没有正确地说出生日悖论。你的评论是:“如果你班上有23名学生,你和另一名学生在同一天过生日的可能性有多大?”;实际的措辞应该是这样的:如果班上有23个学生,他们中至少有2个有相同的生日的可能性有多大?同样不清楚的是,他是否在询问Python语句
year=
birth=
,或者生日悖论本身是如何运作的。