number_of_people = 10; # This is a empty array to hold the probs people_probs = [] for i in range(1,number_of_people): prob = (365-i)/365.0 people_probs.append(prob) print "The prob is: {:.3f}".format(1 - reduce(lambda x,y: x*y, people_probs)) # Better version in a single line - still needs the number of people var print "The prob is: {:.3f}".format(1 - reduce(lambda x,y: x*y, [((365-j)/365.0) for j in range(1,number_of_people)]))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question