Objective: Determine the probability of a "21" from a deck of cards using Monte Carlo (simulation) techniques.
Using Python (or R) write a routine to calculate the probability of getting exactly 21 in a draw from a card deck while drawing only 3 cards. You can easily simulate the deck as the following array;
You will not do this from a direct calculation, but using Monte Carlo techniques. The Monte Carlo technique simulates the conditions of the problem. The pseudo-algorithm is;
1. Randomly select a card from the deck (or item in the array)
import random
# Example arraymy_array = [1, 2, 3, 4, 5]
# Select a random itemrandom_item = random.choice(my_array)
print(random_item)
2. Remember the random item selected (not shown in code) and remove it from the array (shown in code)
import random
# Sample arrayarray = [1, 2, 3, 4, 5]
# Select a random item using samplerandom_item = random.sample(array, 1)[0]
# Remove the selected item from the arrayarray.remove(random_item)
print("Selected item:", random_item)print("Updated array:", array)
3. Select 3 cards from the deck. You can do this by removing the card from the deck when selected or by excluding the index of the card selected from any additional selections. If the cards add to 21, increment a second counter (this is your success counter).
4. Using 100 * number of 21's selected/number of attempts is your sampling probability.
5. Run it 5 times with runs of 1000 attempts and 10,000 attempts and report your results and report results each time (n, s, p) where n = number of attempts, s = number of successes, and p is the calculated probability. Give n in %.
| # of Attempts | # of Successes | Probability of Success |
| 1000 | ||
| 1000 | ||
| 1000 | ||
| 1000 | ||
| 1000 | ||
| 10000 | ||
| 10000 | ||
| 10000 | ||
| 10000 | ||
| 100000 |
This is a formal engineering report. Your code should be in the appendix. You may use AI to help with the coding. You may freely discuss your approach on Assignment 3 Discussion
Report Format (Details at Submission Guidelines (Engineering Reports) )
Cover - Name/Date/Class/Assignment #
Problem Statement - Copy/Paste and then modify to state problem
Methodology - The approach to the problem, not code, equations and explanation here
Results -Be sure to answer the problem asked in the problem statement
Conclusion - This can be short, any additional notes you want to make here
Appendices - Code or any additional information here