import random

initialNumberOfAtoms = int(input("Please enter the initial number of atoms: "))
currentNumberOfAtoms = initialNumberOfAtoms
chanceOfDecay = int(input("\nPlease enter a value for the chance of an atom decaying i.e. 1/x: 1/"))

seconds = 0
halfLifeFound = False

print("\nSeconds = %i\nNumber of Atoms = %i\n" %(seconds, currentNumberOfAtoms))
seconds += 1
while currentNumberOfAtoms > 0:
    for atom in range(0, currentNumberOfAtoms):
        decayOrNot = random.randint(0, chanceOfDecay - 1)
        if decayOrNot == 1:
            currentNumberOfAtoms -= 1
    print("Seconds = %i\nNumber of Atoms = %i\n" %(seconds, currentNumberOfAtoms))      
    if halfLifeFound == False:
        if currentNumberOfAtoms <= initialNumberOfAtoms/2:
            halfDecayedTime = seconds
            halfLifeFound = True
    seconds += 1  

print("The half life for this sample is between %d and %d seconds." %(halfDecayedTime - 1, halfDecayedTime)) 





