Pages

Monday, June 23, 2014

Python code to Find the probability of obtaining at least one 6 when 5 dice are thrown

Q. No. 3

Find the probability of obtaining at least one 6 when 5 dice are thrown.

Answer :

The python code is as follows :
s=0
tries=0
for first in range(1,7):
    for second in range(1,7):
        for third in range(1,7):
            for fourth in range(1,7):
                for fifth in range(1,7):
                    if first==6:
                        s+=1
                    elif second==6:
                        s+=1
                    elif third==6:
                        s+=1
                    elif fourth==6:
                        s+=1
                    elif fifth==6:
                        s+=1
                    tries+=1
print(float(s)/tries)

#Ans : 0.5981224279835391
#>>> tries
#7776
#>>> s
#4651 

CLICK HERE FOR ANSWER TO Q. No. 4

0 comments:

Post a Comment

Receive all updates via Facebook. Just Click the Like Button Below...