In [15]:
import random
countries = ["switzerland", "poland", "croatia", "portugal", "wales", "northern_ireland", "hungary", "belgium", "germany", "slovakia", "italy", "spain", "france", "ireland", "england", "iceland"]
round_name = []
game_result = {"tournament_round": "", "home": "", "rival": "", "result": [0,0], "win": False}
tournament_result = {}
round_count = 1
while round_count < len(countries):
round_name.append(round_count)
round_count = round_count * 2
def set_result(home, rival, tournament_round):
home_team_goals = 0
rival_team_goals = 0
while home_team_goals == rival_team_goals:
home_team_goals = random.randint(0, 10)
rival_team_goals = random.randint(0, 10)
game_result["home"] = home
game_result["rival"] = rival
game_result["result"] = [home_team_goals, rival_team_goals]
game_result["tournament_round"] = "1/" + str(tournament_round)
if home_team_goals > rival_team_goals:
game_result["win"] = True
break
elif home_team_goals < rival_team_goals:
game_result["win"] = False
break
return game_result.copy()
def get_results(country):
results = []
for name1 in round_name:
for name2 in tournament_result[str(name1)]:
if name2["home"] == country or name2["rival"] == country:
results.append(name2)
return results
for name in reversed(round_name):
count = 0
games = []
while count < name:
games.append(set_result(countries[count], countries[count + 1], name))
if (games[count].get("win")):
del countries[count + 1]
else:
del countries[count]
count = count + 1
tournament_result.setdefault(str(name))
tournament_result[str(name)] = games.copy()
print("Winner:", countries[0], "!!!\nWith games result: \n", get_results(countries[0]))
print ("\n", get_results("poland"))