# Homework 4
# YOUR NAME HERE

import math

# returns x**k/k!
# WORKS AS IS
def term(x, k):
    result = 1
    for i in range(1, k+1):
        result *= x/i
    return result

# returns approximation to e to the power of x using n>0 terms
# use for loop and range function
# don't use any math library functions
# dont use the ** operator
# dont use your factorial or power functions
# use your term function
def exp(x, n):
    return None #FIXME

# return True if n is prime, False otherwise
# a prime is an integer greater than 1,
# having only the positive integer divisors 1 and n
def isPrime(n):
    return None #FIXME

# return the square root of x
# assume x > 0
# use for loop and range function
# don't use any math library functions
# dont use the ** operator
# dont use your factorial or power functions
# use your term function
# assume x is a non-negative
def sqrt(x):
    return None #FIXME

# WORKS AS IS
def collatz(n):
    if (n%2==0):
        return n//2
    else:
        return 3*n + 1

# count the number of times it takes for repeated applications
# of the collatz function to reach the value of 1
# assume n is a positive integer

def collatzCount(n):
    return None #FIXME       

# Testing code
def main():
    print("term")
    print(term(3,5), "should be 2.025")
    print()

    print("exp")
    print(exp(0,1000), "should be close to", math.exp(0))
    print(exp(1,1), "should be close to", math.exp(1))
    print(exp(1,10), "should be closer to", math.exp(1))
    print(exp(1,100), "should be closer to", math.exp(1))
    print(exp(1,1000), "should be closer to", math.exp(1))
    print()

    print("isPrime")
    print("-5:", isPrime(-5), "should be False")
    print("0:", isPrime(0), "should be False")
    print("1:", isPrime(1), "should be False")
    print("2:", isPrime(2), "should be True")
    print("3:", isPrime(3), "should be True")
    print("37:", isPrime(37), "should be True")
    print("57:", isPrime(57), "should be False")
    print("73:", isPrime(73), "should be True")
    print("100:", isPrime(100), "should be False")
    print()
    
    print("square root")
    print(sqrt(1), "should be very close to", math.sqrt(1))
    print(sqrt(2), "should be very close to", math.sqrt(2))
    print(sqrt(3), "should be very close to", math.sqrt(3))
    print(sqrt(4), "should be very close to", math.sqrt(4))
    print(sqrt(100), "should be very close to", math.sqrt(100))
    print()
    
    print("collatz")
    print(collatz(3), "should be 10")
    print()
    
    print("collatzCount")
    print(collatzCount(1), "should be 0")
    print(collatzCount(2), "should be 1")
    print(collatzCount(3), "should be 7")
    print(collatzCount(4), "should be 2")
    print(collatzCount(5), "should be 5")
    print(collatzCount(6), "should be 8")
    print(collatzCount(7), "should be 16")
    print(collatzCount(8), "should be 3")
    
main()
