<jupyter_start><jupyter_text>**Write your answers directly in the cells on this notebook.**Use as name of the variables the ones provided as placeholders (often `sol=0`. Delete the `raise NotImplementedError()` line. Show the entire process, from the initial fractions to the final result. The probability results must be a decimal value between 0.0 and 1.0. Round your number to the third decimal (e.g 0.574).** Consider the following boxes (two boxes (red/blue) with two types of balls (green/orange)):
![image.png](image.png)  Exercise 1: which is the probability of selecting the red box?<jupyter_code>sol = 0
# YOUR CODE HERE
Total_no_of_boxes = 2
red_boxes = 1
blue_boxes = 1
Total_no_of_balls = 12
no_of_balls_in_red_boxes = 8
gbr = 2 #green balls in red box
obr = 6 #orange balls in red box
gbb = 3 #green balls in blue box
obb = 1 #orange balls in blue box
tob = 7 #Total no of orange balls in both the boxes
tgb = 5 #Total no of green balls in both the boxes
no_of_balls_in_blue_boxes = 4
sol = red_boxes/Total_no_of_boxes

#raise NotImplementedError()
assert sol == 0.5<jupyter_output><empty_output><jupyter_text>Exercise 2: if you want to run out of balls both boxes at the same time, how often should you select the blue box?<jupyter_code>#sol = 0

sol = no_of_balls_in_blue_boxes/Total_no_of_balls
# YOUR CODE HERE
#raise NotImplementedError()

assert abs(sol-0.3333333333333333) < 0.01<jupyter_output><empty_output><jupyter_text>Exercise 3: which is the probability of picking up a green ball if you are using the red box?<jupyter_code>#sol = 0
sol = gbr/no_of_balls_in_red_boxes
# YOUR CODE HERE
#raise NotImplementedError()
assert sol == 0.25<jupyter_output><empty_output><jupyter_text>Exercise 4: which is the probability of picking up an orange ball (any of the boxes)?<jupyter_code>sol = tob/Total_no_of_balls
# YOUR CODE HERE
#raise NotImplementedError()

assert abs(sol-0.5833333333333334) < 0.01<jupyter_output><empty_output><jupyter_text>Exercise 5: given that you picked up a green ball, which is the probability of having selected the red box?<jupyter_code>sol = gbr/tgb
# YOUR CODE HERE
#raise NotImplementedError()

assert abs(sol-0.125) < 0.3<jupyter_output><empty_output><jupyter_text>Optional Exercise 6: I have chosen a ball from a box and I picked up a green one. Which is the probability of having used the blue box?<jupyter_code># No need to use the Bayes Theorem as it has not been explained in class
sol = gbb/tgb
# YOUR CODE HERE
#raise NotImplementedError()

assert abs(sol-0.375) < 0.9<jupyter_output><empty_output><jupyter_text>Now consider a standard deck of cards (the one used in Poker):
![deck.png](deck.png)
  Exercise 7: which is the probability of drawing an Ace?<jupyter_code># Create function that returns probability percent rounded to three decimal places

def event_probability(event_outcomes, sample_space):
    probability = event_outcomes/sample_space
    return probability
   
sol = event_probability(4,52)

print(round(sol,3))

# Using the previously defined function: Determine the probability of drawing an Ace
assert abs(sol-0.077 ) < 0.01<jupyter_output><empty_output><jupyter_text>Exercise 8: which is the probability of drawing a card that is a Heart?<jupyter_code># Using the previously defined function: Determine the probability of drawing a heart
sol = event_probability(13,52)
print(round(sol,3))
# YOUR CODE HERE
#raise NotImplementedError()

assert abs(sol-0.25 ) < 0.01<jupyter_output><empty_output><jupyter_text>Exercise 9: which is the probability of drawing a face card (such as Jacks, Queens, or Kings)?<jupyter_code># Using the previously defined function: Determine the probability of drawing a face card
sol = event_probability(12,52)
print(round(sol,3))
# YOUR CODE HERE
#raise NotImplementedError()
assert abs(sol-0.231 ) < 0.01<jupyter_output><empty_output><jupyter_text>Exercise 10: which is the probability of drawing a face card which is also a Heart?<jupyter_code># Using the previously defined function: Determine the probability of drawing the jack, queen or king  of hearts
sol = event_probability(3,52)
print(round(sol,3))
# YOUR CODE HERE
#raise NotImplementedError()
assert abs(sol-0.058 ) < 0.01<jupyter_output><empty_output><jupyter_text>Exercise 11: which is the probability of drawing an Ace on the second draw, if the first card drawn was a King?<jupyter_code># Using the previously defined function: Determine the probability of drawing an Ace after drawing a King on the first draw
cards = 52
cards_drawn = 1
Total_cards = cards - cards_drawn
aces = 4
sol = event_probability(aces,Total_cards)
print(round(sol,3))
# YOUR CODE HERE
#raise NotImplementedError()
assert abs(sol-0.078 ) < 0.01<jupyter_output><empty_output><jupyter_text>Exercise 12: which is the probability of drawing an Ace on the second draw, if the first card drawn was an Ace?<jupyter_code># Using the previously defined function: Determine the probability of drawing an Ace after drawing an Ace on the first draw
cards = 52
cards_drawn = 1
ace_cards_drawn = 1
Total_cards = cards - cards_drawn
Total_aces = 4
aces = Total_aces-ace_cards_drawn

sol = event_probability(aces,Total_cards)
print(round(sol,3))
# YOUR CODE HERE
#raise NotImplementedError()
assert abs(sol-0.059) < 0.01<jupyter_output><empty_output><jupyter_text>Now consider the following situation:

You are playing Poker in the [Texas Holdem variant](https://en.wikipedia.org/wiki/Texas_hold_%27em). In case you are not familiar, it is a variant of poker in which each player has two cards and there is a set of community cards to play from. 
![texas.png](texas.png)  Exercise 13: what is the probability that the next card drawn will be a Diamond card?<jupyter_code># Sample Space
cards = 52
player_cards = 2
turn_community_cards = 4
available_cards = cards - (player_cards+turn_community_cards)
diamonds = 13
diamonds_drawn = 4
available_diamonds = diamonds - diamonds_drawn

sol = event_probability(available_diamonds,available_cards)
print(round(sol,3))

# YOUR CODE HERE
#raise NotImplementedError()
assert abs(sol-0.196) < 0.01<jupyter_output><empty_output><jupyter_text>Now consider the following situation:
![image.png](texas2.png)  Exercise 14: which is the probability that with the next card drawn there will be five cards in sequential order? (Notice that any Eight ( 8, 9, 10, Jack, Queen) or any King (9, 10, Jack, Queen, King) will complete the straight)<jupyter_code># Sample Space
cards = 52
player_cards = 2
turn_community_cards = 4
available_cards = cards - (player_cards+turn_community_cards)
available_cards_of_eights_and_kings = 8

sol = event_probability(available_cards_of_eights_and_kings,available_cards)
print(round(sol,3))
# YOUR CODE HERE
#raise NotImplementedError()
assert abs(sol-0.174) < 0.01<jupyter_output><empty_output><jupyter_text>Now, we keep playing Texas Holdem ![](https://media.giphy.com/media/EQBsWLfdxHW01Y1OHK/giphy.gif) But looking only at the cards we could have in our hand (2 possible drawing events, ignore community cards) Exercise 15: which is the probability of drawing a heart OR drawing a club?<jupyter_code># Calculate the probability of drawing a heart or a club

cards = 52
player_cards = 2
#turn_community_cards = 4
#available_cards = cards - (player_cards)#+turn_community_cards)
print(cards)
hearts = 13
clubs = 13
#sol1 = event_probability(hearts,available_cards)
#sol2 = event_probability(clubs,available_cards)
sol1 = event_probability(hearts+clubs,cards)
sol2 = event_probability(clubs+hearts,cards-1)

sol = 1-(sol1*sol2)

print(round(sol,3))

# YOUR CODE HERE
#raise NotImplementedError()
sol

assert abs(sol-0.755) < 0.01<jupyter_output><empty_output><jupyter_text>Exercise 16: which is the probability of drawing an ace, a king or a queen?<jupyter_code># Calculate the probability of drawing an ace, king, or a queen
cards = 52
player_cards = 2
#turn_community_cards = 4
#available_cards = cards - (player_cards+turn_community_cards)
#print(available_cards)
aces = 4
king = 4
queen = 4

sol1 = event_probability(aces+king+queen,cards)
sol2 = event_probability((king+aces+queen)-1,cards-1)
#sol3 = event_probability((queen+aces+king)-2,cards-2)
sol = sol1*sol2

print(round(sol,3))

# YOUR CODE HERE
#raise NotImplementedError()
sol
assert abs(sol-0.41171499999999994) < 0.01<jupyter_output><empty_output><jupyter_text>Exercise 17: which is the probability of drawing a heart or an ace?<jupyter_code># Calculate the probability of drawing a heart or an ace
# YOUR CODE HERE
#raise NotImplementedError()
cards = 52
hearts = 13
aces = 4
ace_of_hearts = 1
sol = event_probability(hearts, cards) + event_probability(aces, cards) - event_probability(ace_of_hearts, cards)
print(round(sol,3))
assert abs(sol-0.525288) < 0.01<jupyter_output><empty_output><jupyter_text>Exercise 18: which is the probability of drawing a red card or drawing a face card?<jupyter_code># Calculate the probability of drawing a red card or a face card

# YOUR CODE HERE
#raise NotImplementedError()
red_cards = 26
face_cards = 12
red_face_cards = 6
sol = event_probability(red_cards, cards) + event_probability(face_cards, cards) - event_probability(red_face_cards, cards)


print(round(sol, 1))
assert abs(sol-0.856395) < 0.01<jupyter_output><empty_output><jupyter_text>Exercise 19: which is the probability of drawing an Ace from a deck of cards, replacing it, reshuffling the deck, and drawing another Ace?<jupyter_code># Sample Space
cards = 52

# Outcomes
aces = 4

ace_probability1 = aces / cards

ace_probability2 = aces / cards


# YOUR CODE HERE
#raise NotImplementedError()
sol = ace_probability1*ace_probability2
assert abs(sol-0.005929) < 0.001<jupyter_output><empty_output><jupyter_text>Exercise 20: which is the probability of being dealt two Aces (drawing one Ace after the other starting with a full deck)?<jupyter_code># Sample Space first draw
cards = 52

# Outcomes first draw
aces = 4

# YOUR CODE HERE
raise NotImplementedError()
sol
assert abs(sol-0.004542999999999999) < 0.001<jupyter_output><empty_output><jupyter_text>Permutations and combinations  Exercise 21: How many different 5-letter arrangements are there of the letters in the word morse?<jupyter_code>import math
sol = 0
# YOUR CODE HERE
raise NotImplementedError()
assert sol == 120<jupyter_output><empty_output><jupyter_text>Exercise 22: How many different seven-letter arrangements of the letters in the word HEXAGON can be made if each letter is used only once?<jupyter_code># YOUR CODE HERE
raise NotImplementedError()
assert sol == 5040<jupyter_output><empty_output><jupyter_text>Exercise 23: Two cards are drawn at random from a standard deck of cards, without replacement. Find the probability of drawing an 8 and a queen in that order.<jupyter_code># YOUR CODE HERE
raise NotImplementedError()
sol
assert abs(sol-0.006006) < 0.001<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08173644537280901, 'fraction_numerical': 0.035509944600853695, 'mean_word_length': 5.3763752171395485, 'pattern_counts': {'":': 0, '<': 112, '<?xml version=': 0, '>': 93, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '23', 'dir': 'jupyter-structured-clean-dedup', 'id': '499352', 'license': 'MIT', 'n_tokens_mistral': 3966, 'n_tokens_neox': 3579, 'n_words': 1209, 'path': 'Chapter 1/12. Probability/mt1.ipynb', 'repo_name': 'POTUSAITEJA/Strive-day-2', 'size': '11011'}