Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Modelling radioactive decay
#!/usr/bin/env python
## sudo apt-get install gnuplot-x1
from random import randint
particles = [] ## create an empty list
results = [] ## create a blank list for the results
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)
particles.append(face)
for items in particles: ## read the array back and remove 'face up'
if items == 6:
max_count -=1
particles = [] ## reset particles list
results.append(max_count)
graph = open("decay_graph", "w")
print ("The results from the experiment")
print ("--- ------- ---- --- ----------")
print ("\n")
c=1
for items in results:
graph.write(str(c) + " " + str(items) +"\n")
print (str(c) + " " + str(items))
c +=1
graph.close()
print ("\n")
print ("Displaying your graph with gnuplot")
print ("---------- ---- ----- ---- -------")
print ("\n")
print ("If you have not installed gnuplot then install it now: sudo apt-get install gnuplot-x1")
print ("\n")
print ("Start up a terminal window and naviage to home/pi/documents")
print ("\n")
print ("Start gnuplot")
print ("""plot "decay_graph" """)
print ("\n")
print ("Going further")
print ("Go back to the code and try increasing the original starting number of cubes")
@uktechreviews
Owner

first commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment