Two of a kind
अब चलिए सिमुलेशन का उपयोग करके probabilities का अनुमान लगाते हैं. मान लीजिए आपको अपने दोस्त के घर पोकर खेलने का न्योता मिला है. इस रूपांतर में, आपको 5 कार्ड बांटे जाते हैं और बेहतर hand वाला खिलाड़ी जीतता है. आप कुछ खास hands मिलने की probabilities का अनुमान लगाने के लिए सिमुलेशन का उपयोग करेंगे. चलिए कम-से-कम एक "two of a kind" मिलने की probability का अनुमान लगाते हैं. Two of a kind तब होता है जब आपको एक ही numeric value वाले लेकिन अलग suites के दो कार्ड मिलते हैं (जैसे, 2 of hearts, 2 of spades, और बाकी 3 अन्य कार्ड).
इस अभ्यास के अंत तक, आप जान जाएंगे कि कार्ड गेम्स की probabilities निकालने के लिए सिमुलेशन का उपयोग कैसे करें.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Statistical Simulation
अभ्यास निर्देश
- हाथ बाँटें (Deal the hand): for लूप में
deck_of_cardsको शफल करें. फिर शुरुआती 5 कार्ड चुनकर उन्हें अपनाhandमानें. - numeric values गिनें:
get()मेथड का उपयोग करके डिक्शनरीcards_in_handबनाएँ, जोhandमें हरnumeric_valueकी गिनती रखे. - Two of a kind? जाँचें कि
cards_in_handमें सबसे बड़ा मान2के बराबर या उससे बड़ा है या नहीं, ताकि पता चले कि हमारे पास कम-से-कम एक two of a kind है. अगर हाँ, तोtwo_kindबढ़ाएँ.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Shuffle deck & count card occurrences in the hand
n_sims, two_kind = 10000, 0
for i in range(n_sims):
____
hand, cards_in_hand = deck_of_cards[0:5], {}
for [suite, numeric_value] in hand:
# Count occurrences of each numeric value
cards_in_hand[numeric_value] = cards_in_hand.____(numeric_value, 0) + 1
# Condition for getting at least 2 of a kind
if ____ >=2:
two_kind += 1
print("Probability of seeing at least two of a kind = {} ".format(two_kind/n_sims))