python3计算234游戏概率
#!/usr/bin/env python # -*- coding: UTF-8 -*- import math def a(n): result = 1 for i in range(1, int(n) + 1): result *= i return result def calculate_probability(x, y, z): global b, c b = 1 c = 1 if x > 9 or y > 9 or z > 9: return "Invalid input. x, y, and z should be less than or equal to 9." if x != y and x != z and y != z: b = 6 elif (x == y and x != z) or (x == z and x != y) or (y == z and y != x): b = 3 result = (a(9) ** 4 * a(18)) * b / (a(27) * (a(x) * a(y) * a(z) * a(9 - x) * a(9 - y) * a(9 - z))) * 100 return f"{result:.5f}%" if __name__ == "__main__": x, y, z = map(int, input("Enter the values of x, y, z separated by space: ").split()) result = calculate_probability(x, y, z) print(result)
评论: