CoCalc Public FilesDeck cards dicussion problem.ipynbOpen with one click!
Authors: MIRALIA MOREAU, Johann Thiel
Views : 145
Compute Environment: Ubuntu 20.04 (Default)

For this problem we need to find the probability for at least three red cards are drew in 5 cards that was drawing from a standard deck. We know that the set of deck cards is a total of 52 cards with two colors, half black and half red. First we need to create a function to draw the cards from the deck in order to see if there is at least 3 red cards. And then we need to randomly shuffle the deck which is a variable that is created to represent both colors, then we will create a if then statement and then calculate the probability.

In [12]:
import numpy as np def cards(): deck=["black" for a in range(26)]+["red" for a in range(26)] np.random.shuffle(deck) thefirstfivecards=deck[:5] number_of_redcards=thefirstfivecards.count("red") if number_of_redcards>=3: return 1 else: return 0
In [10]:
iterations=100000 result =[cards() for a in range(iterations)]
In [13]:

My code does not run to tell me the probalibity for at least 3 red cards,but I believe the probability might be about 49 to 50 percent.