import random
def print_intro():
print("排球比赛模拟程序")
print("-------------------------------")
def input_teams():
team1_ability = float(input("请输入第一个球队的能力值:"))
team2_ability = float(input("请输入第二个球队的能力值:"))
return team1_ability, team2_ability
def simulate_match(team1_ability, team2_ability, num_simulations):
team1_wins = 0
team2_wins = 0
for _ in range(num_simulations):
team1_score = 0
team2_score = 0
for _ in range(4): # 模拟前4局比赛
while True:
team1_score += random.randint(0, 3)
team2_score += random.randint(0, 3)
if abs(team1_score - team2_score) >= 2 and max(team1_score, team2_score) >= 25:
break
while True:
team1_score += random.randint(0, 3)
team2_score += random.randint(0, 3)
if max(team1_score, team2_score) >= 15 and abs(team1_score - team2_score) >= 2:
break
if team1_score > team2_score:
team1_wins += 1
else:
team2_wins += 1
return team1_wins / num_simulations, team2_wins / num_simulations
def output_results(team1_win_prob, team2_win_prob):
print("\n模拟结果:")
print(f"第一个球队获胜的概率:{team1_win_prob:.2%}")
print(f"第二个球队获胜的概率:{team2_win_prob:.2%}")
print("信计1班46号")
def main():
print_intro()
team1_ability, team2_ability = input_teams()
num_simulations = int(input("请输入模拟比赛的次数:"))
team1_win_prob, team2_win_prob = simulate_match(team1_ability, team2_ability, num_simulations)
output_results(team1_win_prob, team2_win_prob)
if name == "main":
main()