Probability Calculation –

--sample space
cards = 52
outcome
aces = 4
Divide possible outcomes with sample test
ace_probability = aces / cards
Print probability rounded to two decimal places
print(round(ace_probability, 2))


Output:
0.08


The probability of drawing an Ace from a standard deck is 0.08. To determine probability in percentage form, simply multiply by 100.
-- Ace Probability Percent Code
ace_probability_percent = ace_probability * 100
Print probability percent rounded to one decimal place
print(str(round(ace_probability_percent, 0)) + '%')
Output :

8.0%
The probability of drawing an Ace as a percent is 8%.
---Create function that returns probability percent rounded to one decimal place
def event_probability(event_outcomes, sample_space):
probability = (event_outcomes / sample_space)*100
return round(probability, 1)
sample Space
cards = 52
Determine the probability of Drawing heart
hearts = 13
heart_probability = event_probability(hearts, cards)
Print each probability
print(str(heart_probability) + '%')


Output:
25.0%
Determine the probability of drawing a face card
face_cards = 12
face_card_probability = event_probability(face_cards, cards)
print(str(face_card_probability) + '%')

Output:
23.1%
---Determine the probability of drawing the queen of hearts
queen_of_hearts = 1
queen_of_hearts_probability = event_probability(queen_of_hearts, cards)
print(str(queen_of_hearts_probability) + '%')


Output:
1.9%
---Sample Space
cards = 52
cards_drawn = 1
cards = cards - cards_drawn
Determine the probability of drawing an Ace after drawing a King on the first draw
aces = 4
ace_probability1 = event_probability(aces, cards)
Determine the probability of drawing an Ace after drawing an Ace on the first draw
aces_drawn = 1
aces = aces - aces_drawn
ace_probability2 = event_probability(aces, cards)
Print each probability
print(ace_probability1)
print(ace_probability2)

Output:
7.8
5.9

-Drawing a heart or drawing a club;
-Drawing an ace, a king or a queen.

-Sample Space
cards = 52
Calculate the probability of drawing a heart or a club
hearts = 13
clubs = 13
heart_or_club = event_probability(hearts, cards) + event_probability(clubs, cards)
Calculate the probability of drawing an ace, king, or a queen
aces = 4
kings = 4
queens = 4
ace_king_or_queen = event_probability(aces, cards) + event_probability(kings, cards) + event_probability(queens, cards)
print(heart_or_club)
print(ace_king_or_queen)


Output:
50.0
23.1

Leave a Reply