A classic GCSE Physics experiment using plastic cubes to model random radioactive decay can be modelled and simulated with Python.

You can change the number of starting cubes by editing the line max_count = 100

The whole experiment is carried out before displaying any results!

The results are saved to a file called decay_graph

#!/usr/bin/env python

from random import randint

particles = []                  ## create an empty list
results = []                    ## create a blank list 
max_count = 100             ## start with this number of cubes

while (max_count > 1) :
    for i in range (max_count):  ## populate array with random dice throws
        face = randint(1,6)
    for items in particles:     ## read the array back and remove 'face up'
        if items == 6:
            max_count -=1
    particles = []              ## reset particles list

graph = open("decay_graph", "w")

print ("The results from the experiment")
print ("--- ------- ---- --- ----------")
print ("n")

for items in results:
    graph.write(str(c) + " " + str(items) +"n")
    print (str(c) + " " + str(items))
    c +=1

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.