Created
March 17, 2021 23:27
-
-
Save crissilvaeng/a25c7a80a6065936e76d750292078a2a to your computer and use it in GitHub Desktop.
Python League
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import combinations | |
from random import choice | |
players = ['Cristina', 'Rodrigo', 'Moises', 'Wagner', 'Arthur'] | |
league = list(combinations(players, 2)) | |
print(league) | |
def victory_host(ranking, host, away): | |
ranking[host] = ranking.get(host, 0) + 3 | |
ranking[away] = ranking.get(away, 0) - 3 | |
def victory_away(ranking, host, away): | |
ranking[host] = ranking.get(host, 0) - 3 | |
ranking[away] = ranking.get(away, 0) + 3 | |
def draw(ranking, host, away): | |
ranking[host] = ranking.get(host, 0) + 1 | |
ranking[away] = ranking.get(away, 0) + 1 | |
handlers = { 'host.win': victory_host, 'away.win': victory_away, 'draw': draw } | |
ranking = {} | |
for game in league: | |
result = choice(list(handlers.keys())) | |
handler = handlers.get(result) | |
handler(ranking, game[0], game[1]) | |
print(f'[{result.upper()}]\t{game[0]} x {game[1]}') | |
print(ranking) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment