Skip to content
Econowmics
Menu
  • Home
  • Economics
    • Econometrics
    • Economics and History
    • Macroeconomics
    • Microeconomics
    • Miscellaneous
      • Awards and Honors
      • Economic Schools of Thought
      • Economic Quotes
      • Economic Videos
    • Terms and Concepts
  • Cognitive Biases
  • Data Analysis
    • Statistics
    • Python Programming
  • Contact
Menu
Penalty Kicks - Econowmics

[Python] Penalty Kicks Simulator

Posted on

Action Bias Among Elite Soccer Goalkeepers: The Case of Penalty Kicks’. Thompson reported: The academics analyzed 286 penalty kicks and found that 94 per cent of the time the goalies dived to the right or the left – even though the chances of stopping the ball were highest when the goalie stayed in the center. If that’s true, why do goalies almost always dive off to one side? Because, the academics theorised, the goalies are afraid of looking as if they’re doing nothing – and then missing the ball. Diving to one side, even if it decreases the chance of them catching the ball, makes them appear decisive. ‘They want to show that they’re doing something,’ says Michael Bar-Eli, one of the study’s authors. ‘Otherwise they look helpless, like they don’t know what to do.’

Pippa Malmgren, Signals: How Everyday Signs Can Help Us Navigate the World’s Turbulent Economy

 

Penalty Kicks - Econowmics
Foto von Pixabay von Pexels

 

Penalty kicks are exciting, especially if they are awarded to the side that you are supporting. No matter how good the penalty takers or the goalkeepers of both sides are, luck still plays a major role in penalty shootouts. Many famous players with large streaks of scoring their penalties have lost a very important one, like Roberto Baggio who missed his penalty against Brazil in 1994 World Cup Finals.

 

 

https://www.youtube.com/watch?v=fpbkRApq9qY

 

 

A very simplified model of penalty kicks could be to consider two random variables (the goalkeeper and the penalty kicker), where each randomly choose a value (a direction to shoot or to dive). If these two values are the same (both shoot and dive to the same direction), the penalty is saved and otherwise it is scored. It is a very simplified model, since it does not take into account many other probabilities, such as if the kicker and the keeper both go for the same direction but nevertheless the keeper cannot save the ball and it is scored. However, the model should be enough for a basic analysis of penalty kicks.

Let’s jump to the code:

[pastacode lang=”python” manual=”%23Econowmics.com%0A%0A%23Penalty%20Kick%20Simulation%0A%0A%23Importing%20the%20modules%20I%20need%0Aimport%20random%0A%0A%23The%20Penalty%20is%20taken%20here%0Adef%20Penalty_kick(n)%3A%0A%20%20%20%20%22%22%22This%20function%20simulates%20n%20Penalty%20Kick(s)%22%22%22%0A%20%20%20%20%0A%20%20%20%20%23Initializing%20a%20storage%20for%20all%20the%20results%0A%20%20%20%20total%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20for%20i%20in%20range(1%2Cn%2B1)%3A%0A%20%20%20%20%20%20%20%20%23The%20goalkeeper%20will%20either%20stay%20in%20the%20center%20or%20jump%20to%20any%20of%20the%206%20possible%20states%0A%20%20%20%20%20%20%20%20Goalkeeper%20%3D%20random.choice(%5B’LB’%2C%20’LT’%2C%20’Center’%2C%20’RB’%2C%20’RT’%5D)%0A%20%20%20%20%20%20%20%20%23The%20penalty%20taker%20can%20shoot%20the%20ball%20to%20any%20of%20the%206%20possible%20places%0A%20%20%20%20%20%20%20%20Penalty%20%3D%20random.choice(%5B’LB’%2C%20’LT’%2C%20’Center’%2C%20’RB’%2C%20’RT’%2C%20’Out’%5D)%0A%20%20%20%20%0A%20%20%20%20%20%20%20%20%23Checking%20to%20see%20if%20the%20penalty%20is%20saved%20or%20if%20it%20is%20in%20fact%20scored%0A%20%20%20%20%20%20%20%20if%20Goalkeeper%20%3D%3D%20Penalty%20or%20Penalty%20%3D%3D%20’Out’%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20total.append(%5BGoalkeeper%2C%20Penalty%2C%20%22Saved!%22%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20total.append(%5BGoalkeeper%2C%20Penalty%2C%20%22Goal!%22%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%23return%20total%0A%20%20%20%20return%20total” message=”” highlight=”” provider=”manual”/]

 

So, what does the code do?

I begin by importing the ‘random’ module, which will help me assign random values to a variable. Then the function for the penalty kicks is defined, which works as follows:

First an empty vector is created to store the result of all taken penalties. Then, I run a loop for n times, where in each iteration the penalty kicker randomly kicks the ball in one of the possible alternatives: [Left Bottom, Left Top, Center, Right Bottom, Right Top, Out]. Similarly, in each iteration the keeper would choose a direction from the same set of alternatives, only without ‘out’.

At the final step, the random values assigned to the two variables ‘Penalty’ and ‘Goalkeeper’ are compared. If the two variables have the same value, or if the player has kicked the penalty out, then the penalty is considered to be saved, otherwise it is regarded as scored.

 

Now that we have the function, let’s quickly analyze a simple scenario. If we have 10000 penalties, how many of the penalties that have been shot to the right bottom corner are saved?

[pastacode lang=”python” manual=”Penalties%20%3D%20Penalty_kick(10000)%0A%0A%23Empty%20variables%20used%20for%20counting%0ARB_total%20%3D%200%0ARB_scored%20%3D%200%0A%0A%23For%20loop%20to%20go%20through%20every%20one%20of%20the%20items%20in%20the%20total%20list%0Afor%20Penalty%20in%20Penalties%3A%0A%20%20%20%20if%20Penalty%5B1%5D%20%3D%3D%20’RB’%3A%0A%20%20%20%20%20%20%20%20RB_total%20%2B%3D%201%0A%20%20%20%20%20%20%20%20if%20Penalty%5B2%5D%20%3D%3D%20%22Goal!%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20RB_scored%20%2B%3D%201%0A%20%20%20%20%20%20%20%20%0A%0Aprint%20(%22Total%20Penalties%20in%20the%20right-bottom%20corner%3A%20%7B%7D%20%5Cn%20Scored%3A%20%7B%7D%20%5Cn%20Saved%3A%20%7B%7D%20%5Cn%20Percent%20scored%3A%20%7B%7D%22%20%5C%0A%20%20%20%20%20%20%20%20.format(RB_total%2C%20RB_scored%2C%20RB_total%20-%20RB_scored%2C%20RB_scored%2FRB_total%20))” message=”” highlight=”” provider=”manual”/]

 

Here I simply loop through all penalties, and for those of them which have been shot to the right bottom I check if they have been scored. then using formatting I print the desired output. This is how the final result looks like:

Econowmics - Penalty Kicks

 

Related posts:

Shakespeare's Nightmare: Monkeys on Typewriters
Benford's Law
[Python] Palindrome Checking Function
[Python] Binary Search
[Python] Prime number generator

Anything in here will be replaced on browsers that support the canvas element

  • Amos Tversky
  • Daniel Kahneman
  • cognitive bias
  • Milton Friedman
  • Wealth of Nations
  • Nobel Prize Laureate
  • Adam Smith
  • 20:20 ratio
  • law of small numbers
  • the halo effect
  • wealth inequality
  • income inequality
  • Law of Large Numbers
  • Dow Jones Industrial Average
  • status quo bias
  • Behavioral Economics
  • daniel kahnemann
  • hyperinflation
  • the gambler's fallacy
  • gambler's fallacy
©2023 Econowmics | Design: Newspaperly WordPress Theme