# Arup Guha
# 7/22/2014
# Code for SI@UCF Test #2

# Run the code for each question.
def main():
    q1()
    print("------------------")
    q2()
    print("------------------")    
    q3()
    print("------------------")
    q4()
    print("------------------")
    q5()
    print("------------------")
    q6()
    print("------------------")
    q7()

# Question 1 Trace
def q1():
    str = "ABCDEFGHIJ"
    print(str[2:7])
    print(str[:8])
    print(str[3:])
    print(str[-6:-2])
    print(str[:-5])

# Question 2 Trace
def q2():

    a = 1
    b = 2
    c = a + b
    for i in range(5):
        print("a =",a,"b =",b,"c =",c)
        a = b
        b = c
        c = a + b

# Solution for question 3
def q3():

    # Initial settings.
    total = 0
    term = 0

    # Keep on adding till we get past 6.
    while total <= 6:
        term = term + 1
        total = total + 1/term
        print("After adding 1/",term," sum is ",total, sep="")

    # Here is our final result.
    print("Final result is",term)

# Solution for question 4
def q4():

    # Need first two values.
    prevnum = int(input("Enter your first guess.\n"))
    nextnum = int(input("Enter your next guess.\n"))

    # Stopping condition is given as this.
    while nextnum - prevnum != 20:

        # Update to next iteration.
        prevnum = nextnum
        nextnum = int(input("Enter your next guess.\n"))
    print("Winner, winner chicken dinner!")

# Solution to question 5.
def q5():

    # Go through range.
    for num in range(1, 10000):

        # Add up each proper divisor.
        total = 0
        for i in range(1, num):
            if num%i == 0:
                total += i
        if total == num:
            print(num)

# Question 6 trace with extra print.
def q6():

    n = 1000000
    cnt = 0
    while n > 0:
        print("Go Knights!")
        n = n//2
        cnt += 1
    print("Printed",cnt,"times.")

# Solution to question 7
def q7():

    height = int(input("Enter the initial height.\n"))
    t = 0;

    # This is key.
    saveheight = height  		

    print("Time\tHeight")
    while height > 0:

        # Print next row then update t.
        print(t,"\t",height)
        t = t + 1				
        height = saveheight - 16*t*t

    # Last row.
    print(t, "\t", 0)

main()
    
