Skip to content

Instantly share code, notes, and snippets.

@rohanrhu
Created October 20, 2022 21:49
Show Gist options
  • Save rohanrhu/34831dd8e25dc5d65480419bca8f741c to your computer and use it in GitHub Desktop.
Save rohanrhu/34831dd8e25dc5d65480419bca8f741c to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
print("Tournament")
def check(matches_fmt, team):
groups = matches_fmt.split(";")
is_found = False
for group in groups:
matches = group.split(",")
for i in range(len(matches)):
match = matches[i]
parts = match.split(":")
teams = parts[0].split("-")
scores = parts[1].split("-")
ti = 0
if teams[0].lower() == team.lower():
is_found = True
elif teams[1].lower() == team.lower():
is_found = True
ti = 1
else:
continue
if int(scores[ti]) > int(scores[1 - ti]):
other_match = matches[len(matches) - (i + 1)]
other_parts = other_match.split(":")
other_teams = other_parts[0].split("-")
other_scores = other_parts[1].split("-")
oti = -1
if int(other_scores[0]) > int(other_scores[1]):
oti = 0
elif int(other_scores[0]) < int(other_scores[1]):
oti = 1
if oti == -1:
print("Other match had no winner!")
return
else:
print("Next opponent of %s will be %s." % (team.upper(), other_teams[oti]))
return
elif int(scores[ti]) < int(scores[1 - ti]):
print("%s lost the game against %s." % (team.upper(), teams[1 - ti]))
return
if not is_found:
print(team.upper() + " doesn't exist!")
# Example:
# UTA-LAC:2-4,DEN-PHX:0-4;PHL-ATL:3-4,MIL-BKN:4-3
matches_fmt = input("Please enter the Conf. Semis results:\n")
team = input("PLease enter the team that you want to check: ")
check(matches_fmt, team)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment