title: how to use probability in python program
body: <p>How do I calculate a probability in python?</p>
  
  <p>Given the dataset <code>A</code> with the following values: <code>[40, 10, 10, 20, 10]</code></p>
  
  <p>How do I calculate the probability of receiving a value of 10? <em>(10 occurs 3 times in total, 3/5 = 0.6</em></p>
  
  <p><strong>Here's the code I've written:</strong></p>
  
  <pre><code>#!/usr/bin/env python3
  """reducer.py"""
  import sys
  
  # Create a dictionary to map marks
  Marksprob = {}
  
  # Get input from stdin
  for line in sys.stdin:
      #Remove spaces from beginning and end of the line
      line = line.strip()
  
      # parse the input from mapper.py
      ClassA, Marks = line.split('\t', 1)
  
  
  # Create function that returns probability percent rounded to one decimal place
  def event_probability(event_outcomes, sample_space):
      probability = (event_outcomes / sample_space) * 100
      return round(probability, 1)
  
  
  # Sample Space
  ClassA = 25
  
  # Determine the probability of drawing a heart
  Marks = 12
  grade_probability = event_probability(Marks, ClassA)
  
  # Print each probability
  print(str(grade_probability) + '%')
  </code></pre>