Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import pandas as pd
- '''1. Estrutura com os Grupos e Seleções, além de seus respectivos scores (Ranking FIFA)'''
- df = pd.read_csv('https://raw.githubusercontent.com/digitalinnovationone/live-coding-evitando-o-7x1-com-python-e-sql/main/data.csv')
- df.head()
- '''2. Classe que representa um time, com suas características e comportamentos:'''
- class Team:
- BEST_SCORE=1837.6 #éééééé do Brasil sil sil
- def __init__(self, content) :
- teamData = content.split('|')
- self.name = teamData[0]
- self.score=float(teamData[1])
- def motivate(self):
- self.last_motivation = random.uniform (70, (self.score*100)/Team.BEST_SCORE )
- return self.last_motivation
- ''' Fase 3 - Simulando a fase Grupos'''
- bestTeamByGroup={}
- for label, content in df.items():
- team1 = Team(content[0])
- team2 = Team(content[1])
- team3 = Team(content[2])
- team4 = Team(content[3])
- bestTeamByGroup[label] = sorted([team1,team2,team3,team4], key=Team.motivate, reverse=True)
- for grupo, motivatedTeams in bestTeamByGroup.items():
- print(f'Grupo {grupo}: ')
- for team in motivatedTeams:
- print(f'Time: {team.name}, Motivação: {team.last_motivation:.2f}')
- print()
- '''4. Simulando as Oitavas de Final (16 melhores seleções)'''
- team1A = bestTeamByGroup['A'][0]
- team2A = bestTeamByGroup['A'][1]
- team1B = bestTeamByGroup['B'][0]
- team2B = bestTeamByGroup['B'][1]
- team1C = bestTeamByGroup['C'][0]
- team2C = bestTeamByGroup['C'][1]
- team1D = bestTeamByGroup['D'][0]
- team2D = bestTeamByGroup['D'][1]
- team1E = bestTeamByGroup['E'][0]
- team2E = bestTeamByGroup['E'][1]
- team1F = bestTeamByGroup['F'][0]
- team2F = bestTeamByGroup['F'][1]
- team1G = bestTeamByGroup['G'][0]
- team2G = bestTeamByGroup['G'][1]
- team1H = bestTeamByGroup['H'][0]
- team2H = bestTeamByGroup['H'][1]
- quarter1 = team1A if team1A.motivate() > team2B.motivate() else team2B
- quarter2 = team1C if team1C.motivate() > team2D.motivate() else team2D
- quarter3 = team1E if team1E.motivate() > team2F.motivate() else team2F
- quarter4 = team1G if team1G.motivate() > team2H.motivate() else team2H
- quarter5 = team1B if team1B.motivate() > team2A.motivate() else team2A
- quarter6 = team1D if team1D.motivate() > team2C.motivate() else team2C
- quarter7 = team1F if team1F.motivate() > team2E.motivate() else team2E
- quarter8 = team1H if team1H.motivate() > team2G.motivate() else team2G
- print('oitavas de final')
- print(f'{team1A.name} ({team1A.last_motivation:.2f}) x {team2B.name} ({team2B.last_motivation:.2f})')
- print(f'{team1C.name} ({team1C.last_motivation:.2f}) x {team2D.name} ({team2D.last_motivation:.2f})')
- print(f'{team1E.name} ({team1E.last_motivation:.2f}) x {team2F.name} ({team2F.last_motivation:.2f})')
- print(f'{team1G.name} ({team1G.last_motivation:.2f}) x {team2H.name} ({team2H.last_motivation:.2f})')
- print(f'{team1B.name} ({team1B.last_motivation:.2f}) x {team2A.name} ({team2A.last_motivation:.2f})')
- print(f'{team1D.name} ({team1D.last_motivation:.2f}) x {team2C.name} ({team2C.last_motivation:.2f})')
- print(f'{team1F.name} ({team1F.last_motivation:.2f}) x {team2E.name} ({team2E.last_motivation:.2f})')
- print(f'{team1H.name} ({team1H.last_motivation:.2f}) x {team2G.name} ({team2G.last_motivation:.2f})')
- '''5. Simulando as Quartas de Final (8 melhores seleções)'''
- semi1 = quarter1 if quarter1.motivate() > quarter2.motivate() else quarter2
- semi2 = quarter3 if quarter3.motivate() > quarter4.motivate() else quarter4
- semi3 = quarter5 if quarter5.motivate() > quarter6.motivate() else quarter6
- semi4 = quarter7 if quarter7.motivate() > quarter8.motivate() else quarter8
- print()
- print("quartas finais")
- print(f'{quarter1.name} ({quarter1.last_motivation:.2f}) x {quarter2.name} ({quarter2.last_motivation:.2f})')
- print(f'{quarter3.name} ({quarter3.last_motivation:.2f}) x {quarter4.name} ({quarter4.last_motivation:.2f})')
- print(f'{quarter5.name} ({quarter5.last_motivation:.2f}) x {quarter6.name} ({quarter6.last_motivation:.2f})')
- print(f'{quarter7.name} ({quarter7.last_motivation:.2f}) x {quarter8.name} ({quarter8.last_motivation:.2f})')
- '''6. Simulando as Semifinais (4 melhores seleções)'''
- final1 = semi1 if semi1.motivate() > semi2.motivate() else semi2
- terceiro1 = semi2 if semi1.last_motivation > semi2.last_motivation else semi1
- final2 = semi3 if semi3.motivate() > semi4.motivate() else semi4
- terceiro2 = semi4 if semi3.last_motivation > semi4.last_motivation else semi3
- print()
- print('semi-fimais')
- print(f'{semi1.name} ({semi1.last_motivation:.2f}) x {semi2.name} ({semi2.last_motivation:.2f})')
- print(f'{semi3.name} ({semi3.last_motivation:.2f}) x {semi4.name} ({semi4.last_motivation:.2f})')
- '''7. Simulando a Final (2 melhores seleções)'''
- winner = final1 if final1.motivate() > final2.motivate() else final2
- second = final1 if final1.last_motivation < final2.last_motivation else final2
- third = terceiro1 if terceiro1.motivate() > final2.motivate() else final2
- fourth = terceiro1 if terceiro1.last_motivation < final2.last_motivation else final2
- print()
- print(f'1º: {winner.name} ({winner.last_motivation:.2f})')
- print(f'2: {second.name} ({second.last_motivation:.2f})')
- print(f'3º: {third.name} ({third.last_motivation:.2f})')
- print(f'4º: {fourth.name} ({fourth.last_motivation:.2f})')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement