import random
class Team:
location: "European"
def __init__(self, rate, name):
self.rate = rate
self.name = name
self.points = 0
self.scored = 0
self.concede = 0
def drawing(t):
half = len(t) #8
sorted_data = sorted(t.items(), key=lambda x: x[1], reverse=True)
top_half = dict(sorted_data[:half])
bottom_half = dict(sorted_data[half:])
print(top_half, bottom_half)
teams = [
Team(89, "bayern"),
Team(90, "arsenal"),
Team(94, "psg"),
Team(89, "mancity"),
Team(86, "barcelona"),
Team(80, "real"),
Team(75, "liverpool"),
Team(73, "aston_villa"),
Team(72, "internazionale"),
Team(69, "united"),
Team(65, "atletico"),
Team(60, "juventus"),
Team(59, "dortmund"),
Team(54, "chelsea"),
Team(53, "milan"),
Team(45, "sporting")
]
# qualif_teams = Team.all_teams
# mylist = sorted(qualif_teams.items, key=lambda x: x[1], reverse=True)
# print(mylist)
# for team in Team.all_teams:
# print(team.name)
# teams_list = Team.all_teams
# print(teams_list)
def match(home_team, away_team):
home_res = 0
away_res = 0
if home_team != away_team:
goals = round(random.random() * 6)
chance = home_team.rate / (home_team.rate + away_team.rate - 5)
for k in range(0, goals):
if chance > random.random():
home_res += 1
else:
away_res += 1
home_team.scored += home_res
home_team.concede += away_res
away_team.concede += home_res
away_team.scored += away_res
if home_res > away_res:
home_team.points += 3
elif home_res == away_res:
home_team.points += 1
away_team.points += 1
else:
away_team.points += 3
print(home_team.points, away_team.points)
return print(f"{home_team.name} - {away_team.name} {home_res}:{away_res}")
for h in teams:
for a in teams:
match(h, a)
arr = []
for t in teams:
arr.append((t.name.capitalize(), t.points, f"{t.scored} - {t.concede}"))
print(arr)
with open('champions.py', 'a', encoding='utf-8') as file:
file.write(f"{arr}\n")