Pages

Monday, June 23, 2014

Python code to find the probability of drawing an ace or a heart from a pack of 52 playing cards

Q. No. 4 :

What is the probability of drawing an ace or a heart from a pack of 52 playing cards?

Answer :

We know that the total number of playing cards are 52.
Among these, there are four types.
  1. Spades
  2. Diamonds
  3. Hearts
  4. Clubs
Hence, the number of heart cards are 13 (52/4).
The number of aces (A's) are four...Among which one is of hearts.
Hence, there are three aces which are not hearts.
Our problem is to draw either a heart card or an ace. Hence, we have to draw any one of these 16 (13+3) cards from total 52 cards.
Therefore the probability is P=16/52.
The python code solution for this problem is given below :
s=0
tries=0
for prob in range(1,53):
    if prob < 17:
        s+=1
    tries+=1
print (float(s)/tries)

##Ans:
##>>>
##0.3076923076923077
##>>> s
##16
##>>> tries
##52
##>>>

CLICK HERE FOR ANSWER TO Q. No. 5

0 comments:

Post a Comment

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