# -*- coding: utf-8 -*-
"""
Review for Term 1:
Unit testing and pre/post conditions

@author: Catherine
"""

#Add in the pre and post conditions for the
#functions. Write unit tests first in the
#command line and then in a seperate script.

def factorial(n):
    if n==0 or n==1:
        return(1)
    else:
        return(n*factorial(n-1))
    
def to_the_power(x,n):
    i=0
    s=1
    while i < n:
        s *=x
        i+=1
    return s

def exp(x,n):
    ans=1
    for i in range(1,n):
        ans += to_the_power(x,i)/factorial(i)
    return ans

def HalfLife(n0, time, order):
    tau = 31.74
    return(n0*exp(-time/tau,order))

def main():
    N0 = float(input("Initial amount of francium: "))
    time = float(input("Time elapsed: "))
    order = int(input("Order of exp: "))
    
    print("\nFrancium left after "+repr(time)+" minutes is:")
    print(HalfLife(N0,time,order))
    
    return

if __name__=="__main__":
    main()