Reformat code to pythonic standards

This commit is contained in:
chris committed 2026-05-27 08:20:30 -04:00
1 parent ea62bdfc0b
commit b1732c07c5
5 files changed
+123 -51

No files matched your search

+29 -12
View File
@@ -9,15 +9,18 @@ from math import comb
def calculate_odds(pool_size: int, draw_count: int) -> int:
"""
Calculate the total number of possible combinations in a set of numbers with a specific draw count.
Calculate the total number of possible combinations in a set of numbers
with a specific draw count.
:param pool_size: Total count of numbers in the pool
:param draw_count: The count of numbers to draw from the pool
:return: The total number of possible combinations
Example:
If a lottery game has a main ball pool of 49 numbers from which 5 numbers are drawn and a pool of
18 numbers from which 1 number is drawn (game ball), calculate the odds of winning that game.
If a lottery game has a main ball pool of 49 numbers from which 5
numbers are drawn and a pool of
18 numbers from which 1 number is drawn (game ball), calculate the
odds of winning that game.
>>> calculate_odds(pool_size=49, draw_count=5)
1906884
@@ -26,7 +29,10 @@ def calculate_odds(pool_size: int, draw_count: int) -> int:
"""
if draw_count < 0 or draw_count > pool_size:
raise ValueError('Integer values must be positive and draw counts must be less than pool size.')
raise ValueError(
'Integer values must be positive and draw counts must be less '
'than pool size.',
)
total_combinations = comb(pool_size, draw_count)
return total_combinations
@@ -35,29 +41,40 @@ def get_odds_of_winning(
main_ball_draw_pool: int,
main_ball_draw_count: int,
game_ball_draw_pool: int,
game_ball_draw_count: int
game_ball_draw_count: int,
) -> str:
"""
Calculate the odds of winning a specific lottery game with one draw
:param main_ball_draw_pool: Total count of numbers in the main ball pool
:param main_ball_draw_count: The count of numbers to draw from the main ball pool
:param main_ball_draw_count: The count of numbers to draw from the
main ball pool
:param game_ball_draw_pool: Total count of numbers in the game ball pool
:param game_ball_draw_count: The count of numbers to draw from the game ball pool
:param game_ball_draw_count: The count of numbers to draw from the
game ball pool
:return: The odds of winning a specific lottery game with one draw
Example:
To calculate the odds of winning a lottery game with 5 numbers drawn from a main ball pool of 49 and
To calculate the odds of winning a lottery game with 5 numbers
drawn from a main ball pool of 49 and
1 number drawn from a game ball pool of 19 numbers.
>>> get_odds_of_winning(main_ball_draw_pool=49, main_ball_draw_count=5, game_ball_draw_pool=18, game_ball_draw_count=1)
>>> get_odds_of_winning(main_ball_draw_pool=49,
main_ball_draw_count=5, game_ball_draw_pool=18,
game_ball_draw_count=1)
'The odds of winning are 1 in 34,323,912'
"""
if (main_ball_draw_count < 0 or main_ball_draw_count > main_ball_draw_pool or
game_ball_draw_count < 0 or game_ball_draw_count > game_ball_draw_pool):
raise ValueError('Integer values must be positive and draw counts must be less than pool size.')
if (
main_ball_draw_count < 0 or main_ball_draw_count >
main_ball_draw_pool or
game_ball_draw_count < 0 or game_ball_draw_count >
game_ball_draw_pool):
raise ValueError(
'Integer values must be positive and draw counts must be less '
'than pool size.',
)
main_ball_odds = calculate_odds(main_ball_draw_pool, main_ball_draw_count)
game_ball_odds = calculate_odds(game_ball_draw_pool, game_ball_draw_count)