This Python script simulates a fictional football (soccer) match between...

August 24, 2025 at 05:32 AM

import time import random #football simulation print ("UCL FINAL 2026 ") rhy = ["real madrid" ,"barcalona"] realmadrid = 0 barcalona = 0 misses = ["hit it off the woodwork", "went wide", "saved by the keeper", "blocked by the defender", "missed", "into the stans", "missed so bad he killed someone in the stans", "offsides" ] rmaplayers = [ "Thibaut Courtois", "Andriy Lunin", "Fran González", "Sergio Mestre", "Dani Carvajal", "Éder Militão", "David Alaba", "Trent Alexander-Arnold", "Raúl Asencio", "Álvaro Carreras", "Fran García", "Antonio Rüdiger", "Ferland Mendy", "Dean Huijsen", "Jude Bellingham", "Eduardo Camavinga", "Federico Valverde", "Aurélien Tchouaméni", "Arda Güler", "Dani Ceballos", "Thiago Pitarch", "Vinícius Júnior", "Endrick", "Kylian Mbappé", "Rodrygo", "Gonzalo García", "Brahim Díaz", "Franco Mastantuono" ] barcaplayers = [ "Marc-André ter Stegen", "Iñaki Peña", "Wojciech Szczęsny", "Joan García", "Diego Kochen", "Andreas Christensen", "Jules Koundé", "Pau Cubarsí", "Ronald Araújo", "Alejandro Balde", "Eric García", "Héctor Fort", "Jofre Torrents", "Gerard Martin", "Frenkie de Jong", "Pedri", "Gavi", "Fermín López", "Marc Casadó", "Dani Olmo", "Lamine Yamal", "Raphinha", "Robert Lewandowski", "Marcus Rashford", "Ferran Torres", "Toni Fernández", "Guille Fernández", "Pedro Fernández Dro", ] q = random.randint(1,9) tiem = 0 tiem2 = 91 tiempo = tiem2 + q while True: if tiempo > tiem: print (f"Minute {tiem}' --- Barcalona {barcalona} - Real Madrid {realmadrid}") tiem += 1 if tiem == 46: print('HALFTIME BREAK ') print(f"OUT {random.choice(rmaplayers)} IN {random.choice(rmaplayers)}") print(f"OUT {random.choice(barcaplayers)} IN {random.choice(barcaplayers)}") time.sleep(5) Q = random.randint(0,5) if Q == 3: R = random.randint(0,1) if R == 1: print (f'minute {tiem} big chance for barcelona but {random.choices(barcaplayers)} {random.choice(misses)}') if R == 0: print (f'minute {tiem} big chance for Madrid but {random.choices(rmaplayers)} {random.choices(misses)} ') e = random.randint(0,15) if e == 5: E = random.randint(0,1) if E == 1: barcalona += 1 print (f'{random.choice(barcaplayers)} scored assisted by {random.choice(barcaplayers)}') if E == 0: realmadrid += 1 print(f'{random.choice(rmaplayers)} scored assited by {random.choice(rmaplayers)}') time.sleep(0.5) else: if realmadrid > barcalona: print (f'REAL MADRID WINS Barcalona {barcalona} - Real Madrid {realmadrid}') break if barcalona > realmadrid: print (F'BARCALONA WINS Barcalona {barcalona} - Real Madrid {realmadrid}') break if barcalona == realmadrid: print(f'TIE Barcalona {barcalona} - Real Madrid {realmadrid}') break

This Python script simulates a fictional football (soccer) match between Real Madrid and Barcelona in the 2026 UEFA Champions League (UCL) final, providing a simulation of match events. Here's a breakdown of what it does:

1. Setup and Initialization:

  • Libraries time and random are imported for managing timing and generating random events.
  • A list of players for both Real Madrid (rmaplayers) and Barcelona (barcaplayers) is defined.
  • A list of possible "miss events" (misses) is created to describe unlucky attempts at scoring goals.
  • The starting scores for both teams are initialized as realmadrid = 0 and barcalona = 0.

2. Match Duration:

  • The match starts at Minute 0 and ends at a random time (tiempo between 91 and 100 minutes) to simulate slight stoppage time.

3. Simulating the Match:

The match progresses minute by minute in an infinite loop. Each iteration represents one in-game minute (tiem variable). This is what happens:

  • Minute Updates: At the start of each minute, the score is printed with the current minute.
  • Halftime Break: At the 46th minute (end of the first half), the code simulates a halftime, announces a few substitutions from the player lists for both teams, and pauses briefly using time.sleep(5).

4. Random Events During the Match:

  • Missed Chances: There is a 1-in-6 chance per minute (when Q == 3) that one of the teams will get a "big chance" but miss. The code selects a player randomly from the respective team and associates a random failure reason (misses).

  • Goals: There is a 1-in-16 chance per minute (when e == 5) that one of the teams will score. When a team scores:

    • A random scorer and random assist provider are picked from that team's player list.
    • The respective team’s score is incremented (barcalona or realmadrid).
  • A small delay of 0.5 seconds is added after each update for better simulation timing.

5. End of Match:

  • When the match time (tiem) exceeds the randomized match duration (tiempo), the game ends.
  • The script checks the score:
    • If realmadrid > barcalona, Real Madrid is declared the winner.
    • If barcalona > realmadrid, Barcelona is declared the winner.
    • If scores are equal, it outputs a "TIE".
  • The loop breaks.

6. Output:

  • Throughout the match, the script prints minute-by-minute updates, including:
    • The current score.
    • Major events such as missed chances and goals.
    • Halftime announcements and substitutions.

Example Outputs:

Example of minute-by-minute updates:

Minute 10' --- Barcalona 0 - Real Madrid 0
Minute 15' big chance for Madrid but ['Kylian Mbappé'] ['missed so bad he killed someone in the stans'] 
['Lamine Yamal'] scored assisted by ['Pedri']
Minute 35' --- Barcalona 1 - Real Madrid 0
HALFTIME BREAK
OUT Eduard Camavinga IN Jude Bellingham
OUT Alejandro Balde IN Ferran Torres
...
Minute 91' --- Barcalona 2 - Real Madrid 3
REAL MADRID WINS Barcalona 2 - Real Madrid 3

Purpose:

This script provides a random yet structured simulation of a football match. It mimics the excitement of a live match by incorporating random events like missed chances, goals, and halftimes. While it does not produce accurate real-world predictions, it serves as a fun, programmatic way to simulate football matches.

Generate your own explanations
Download our vscode extension
Read other generated explanations

Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node