最后一次大作业

发布时间 2023-12-18 22:48:14作者: 过过过过过过

0310033003600350038003000331702906330564

1)模拟体育竞技分析:(不同学号选做不同题目,必做题)‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

a.采用乒乓球比赛规则(学号尾号为0,1,2,3同学必做及格题)。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

(即:一局比赛:‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

在一局比赛中,先得11分的一方为胜方;10平后,先多得2分的一方为胜方。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

一场比赛:‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

单打的淘汰赛采用七局四胜制,双打淘汰赛和团体赛采用五局三胜制。)

import random

class PingPongMatch:
def __init__(self, player1_ability, player2_ability):
self.player1_ability = player1_ability
self.player2_ability = player2_ability

def simulate_match(self, num_matches):
player1_wins = 0
player2_wins = 0
for _ in range(num_matches):
score1, score2 = 0, 0
while not self.game_over(score1, score2):
if random.random() < self.player1_ability:
score1 += 1
else:
score2 += 1
if score1 > score2:
player1_wins += 1
else:
player2_wins += 1
return player1_wins / num_matches, player2_wins / num_matches

def game_over(self, score1, score2):
return (score1 >= 11 or score2 >= 11) and abs(score1 - score2) >= 2

player1_ability = float(input("请输入球员1的能力值(0到1之间的小数):"))
player2_ability = float(input("请输入球员2的能力值(0到1之间的小数):"))
num_matches = int(input("请输入模拟比赛的次数:"))

match = PingPongMatch(player1_ability, player2_ability)
player1_win_prob, player2_win_prob = match.simulate_match(num_matches)
print("22信计1巫巧霞2022310143031")
print(f"球员1获胜的概率为:{player1_win_prob:.2%}")
print(f"球员2获胜的概率为:{player2_win_prob:.2%}")

运用pyinstaller打包可以执行的文件。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

(2)采用篮球或者足球规则模拟比赛,分析体育竞技规则,模拟比赛。(良好),基本要求同上。

pyinstaller your_script.py

 采用乒乓球、羽毛球、篮球、足球等规则中的一种。同时采用循环赛或者晋级赛形式,模拟分析4个队及以上体育竞技,并输出排名。建议可以采用面向对象方法或者改动上面程序。

class Team:
def __init__(self, name):
self.name = name
self.points = 0

def win_match(self):
self.points += 3

def draw_match(self):
self.points += 1

def lose_match(self):
pass

def __str__(self):
return f"Team: {self.name}, Points: {self.points}"


class Match:
def __init__(self, team1, team2, result):
self.team1 = team1
self.team2 = team2
self.result = result

def play_match(self):
if self.result == "win":
self.team1.win_match()
self.team2.lose_match()
elif self.result == "draw":
self.team1.draw_match()
self.team2.draw_match()
elif self.result == "lose":
self.team1.lose_match()
self.team2.win_match()


def simulate_tournament(teams, matches):
for match in matches:
match.play_match()

sorted_teams = sorted(teams, key=lambda x: x.points, reverse=True)
for i, team in enumerate(sorted_teams):
print(f"Rank {i+1}: {team}")

 

team1 = Team("Team A")
team2 = Team("Team B")
team3 = Team("Team C")
team4 = Team("Team D")


match1 = Match(team1, team2, "win")
match2 = Match(team2, team3, "draw")
match3 = Match(team3, team4, "lose")
match4 = Match(team4, team1, "lose")


teams = [team1, team2, team3, team4]
matches = [match1, match2, match3, match4]
simulate_tournament(teams, matches)