Question: The question is asking to write in function in python having the following definition (signature) line def test_for_poker_straight(hand_of_cards) and Integrating this function into the code

The question is asking to write in function in python having the following definition (signature) line "def test_for_poker_straight(hand_of_cards)" and Integrating this function into the code below and using this new function to calculate the probability of being dealt a five card poker straight. you can input (5 cards per 500 dealt)

Note:- A POKER STRAIGHT is here defined as FIVE CONSECUTIVE CARD VALUES.

from random import shuffle import time import math

def ncr(n, r): f = math.factorial return f(n) // f(r) // f(n-r) def make_deck(): value = ['A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'] suit = ['C','H','S','D'] deck = [j+i for j in value for i in suit] return deck

def shuffle_deck(deck, times_to_shuffle=1): for n in range(times_to_shuffle): shuffle(deck)

def test_for_three_clubs_and_two_hearts(hand_of_cards): countClub = 0 countHeart = 0 for card in hand_of_cards: if card[len(card)-1] == 'C': countClub += 1 elif card[len(card)-1] == 'H': countHeart += 1 return 0

def test_for_poker_flush(hand_of_cards): countClub = 0 countHeart = 0 countSpade = 0 countDiamond = 0 for card in hand_of_cards: if card[len(card)-1] == 'C': countClub += 1 elif card[len(card)-1] == 'H': countHeart += 1 elif card[len(card)-1] == 'S': countSpade += 1 else: countDiamond += 1 if(countClub == 5 or countHeart == 5 or countSpade == 5 or countDiamond == 5): return 1; return 0; cards_per_hand = int(input('Enter the number of cards per hand: '))

hands_dealt = int(input('Enter the total number of hands to deal: ')) start_time = time.time() matching_hands = 0 flush_hands = 0 for n in range(hands_dealt): deck_of_cards = make_deck() shuffle_deck(deck_of_cards) hand_of_cards = deck_of_cards[0:cards_per_hand] matching_hands += test_for_three_clubs_and_two_hearts(hand_of_cards) flush_hands += test_for_poker_flush(hand_of_cards)

execution_time = (time.time() - start_time) probability = ncr(13, 3) * ncr(13, 2) / ncr(52, cards_per_hand) probability_flush = (4 * ncr(13, 5) )/ ncr(52, cards_per_hand)

print(' The probability of being dealt three clubs and two hearts is: ', probability) print(' Number of times you have got three clubs and two hearts = ', matching_hands) print(' The probability of being dealt a flush is: ', probability_flush) print(' Number of times you have got a flush = ', flush_hands) print(' Time to execute ',hands_dealt ,' numerical experiments: ', round(execution_time,3), ' seconds ')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!