The Euro 2024 is in full swing. To develop a prediction app, several functions are needed to keep track of, display, and compare matches and predictions.
Define a function match
. The function has 4 parameters:
team1
: name of the home teamteam2
: name of the away teamscore_team1
: number of goals for the home teamscore_team2
: number of goals for the away teamThe function also has two default arguments:
prediction
: boolean indicating whether the score is a prediction or an actual result. The default is False
player
: name of the player who added the prediction. The default is an empty string.The function will store the match in a list where for a result, team1
will be stored in the first position of the list, team2
in the second position, score_team1
in the third position, and score_team2
in the fourth position. For a prediction, the name of the player will also be added to the list.
Define a function is_prediction
. The function takes a list corresponding to a match (see match
function). If the match corresponds to a prediction, the function returns True
, otherwise False
.
Define a function winner
with an argument that corresponds to a list representing a match (see match
function). The function returns the name of the team with the highest score. If the match is a draw, it returns "DRAW"
.
Define a function print_match
with an argument that corresponds to a list representing a match (see match
function). The function prints the match for a result:
Turkey 1-1 Georgia
For a prediction:
Prediction Lewis : Belgium 1-1 Slovakia
Define a function print_matches
with an argument that is a list of matches corresponding to lists (see match
function). The function prints the matches from the list line by line, first giving an overview of the results and then of the predictions:
Results:
Turkey 1-1 Georgia
Portugal 1-1 Czech Republic
Romania 0-0 Ukraine
Belgium 1-1 Slovakia
Poland 2-2 Netherlands
Austria 1-1 France
Poland 2-2 Netherlands
Slovenia 1-1 Denmark
Serbia 1-1 England
Spain 0-0 Croatia
Italy 1-1 Albania
Germany 1-1 Scotland
Hungary 5-5 Switzerland
Predictions:
Prediction Lewis : Belgium 1-1 Slovakia
Prediction Alexander : Belgium 1-1 Slovakia
Define a function check_prediction
with arguments match_result
and prediction
, both corresponding to lists (see match
function). The function returns the points earned for the prediction based on the following rules: