title: Calculating (experimental) probability of head toss
body: <p>I want to calculate the experimental probability of heads in coin toss by generating 0s or 1s randomly and assign 'h' for 0 and 't' for 1 to n. The number of flips is 100.</p>
  <pre><code>import random
  
  array_ht = []
  
  flip_count = 0
  
  while flip_count != 100:
      n = random.randint(0,1)
      if n == 0:
          n = &quot;h&quot;
      elif n == 1:
          n = &quot;t&quot;
      flip_count += 1
      array_ht.append(n)
  
  for x in array_ht:
      h_count = 0
      if x == &quot;h&quot;:
          h_count += 1
  
      print(h_count + &quot;%&quot;)
  </code></pre>
  <p>The for loop looks through every object of array_ht and if it finds an &quot;h&quot;, it adds 1 to the number of head flips. But the code isn't working and just prints &quot;1% 0% 1% 0% 0% ...&quot;</p>
  <p>What should actually happen is for example if sequence generated was '0,1,1,0,0,0,1,1,1' then array_ht = [h,t,t,h,h,h,t,t,t] and probability to be printed is (4/9*100=) 44.444444%.</p>
  <p>Actually we don't need to assign 'h' or 't' to n, we can just look for number of 0s but earlier I had wanted to print array_ht also.</p>