import random
teams = ["France", "Spain", "Poland", "Denmark", "Netherlands", "Germany", "Wales", "England", "Belgium", "Serbia", "Croatia", "Switzerland", "Portugal", "China", "Iran", "Australia", "Saudi Arabia", "Japan", "South Korea", "Brazil", "Ecuador", "Argentina", "Uruguay", "USA", "Costa Rica", "Canada", "Mexico", "Ghana", "Tunisia", "Morocco", "Senegal", "Cameroon"]
first_tier = ["France", "Spain", "Germany", "England", "Portugal", "Brazil", "Argentina", "Netherlands"]
second_tier = ["Poland", "Denmark", "Belgium", "China", "Cameroon", "Uruguay", "Japan", "Croatia"]
groups = []
# assign teams to groups
for i in range(8):
group = []
group.append(first_tier[i])
group.append(second_tier[i])
for j in range(2):
team = random.choice(teams)
while team in first_tier or team in second_tier or team in group:
team = random.choice(teams)
group.append(team)
groups.append(group)
# print groupings
print("Groupings:")
for i in range(8):
print("Group " + chr(ord('A') + i) + ": " + ", ".join(groups[i]))
# generate match schedule
matches = []
for i in range(8):
for j in range(3):
for k in range(j+1, 4):
matches.append((groups[i][j], groups[i][k]))
# print number of matches
print("\nTotal number of matches: " + str(len(matches)))
# function to check if China will play Brazil
def will_play_brazil(stage):
if stage == "group":
for i in range(8):
if "China" in groups[i] and "Brazil" in groups[i]:
return True
return False
elif stage == "knockout":
if (len(matches) - len(groups) * 6) % 8 < 4:
# China is in top half of knockout bracket
if (matches[-1][0] == "China" and matches[-1][1] == "Brazil") or (matches[-1][1] == "China" and matches[-1][0] == "Brazil"):
return True
else:
return False
else:
# China is in bottom half of knockout bracket
if (matches[-5][0] == "China" and matches[-5][1] == "Brazil") or (matches[-5][1] == "China" and matches[-5][0] == "Brazil"):
return True
else:
return False
# check if China will play Brazil
if will_play_brazil("group"):
# print when China will play Brazil (if they do at all)
print("\nChina will play Brazil in the group stage.")
elif will_play_brazil("knockout"):
print("\nChina will play Brazil in the knockout stage.")
else:
print("\nChina will not play Brazil in this World Cup.")