添加odds转概率

This commit is contained in:
2025-10-13 00:57:58 +08:00
parent b73a96d3d1
commit 3b25c18b6a

22
bet_calc.py Normal file
View File

@@ -0,0 +1,22 @@
def american_odds_to_probability(odds: int) -> float:
"""
根据美式赔率计算概率(以小数形式返回)
:param odds: 美式赔率(正数或负数)
:return: 概率0~1之间的小数
"""
if odds > 0:
probability = 100 / (odds + 100)
else:
probability = abs(odds) / (abs(odds) + 100)
return probability
# 示例
if __name__ == "__main__":
odds_list = [+150, -200, +300, -120]
for odds in odds_list:
prob = american_odds_to_probability(odds)
print(f"赔率 {odds}: 概率 {prob:.4f}")